2013-11-06 2 views
0

enter image description hereОтносительные Layout View Трассы

Изображение выше, имеет много проблем, начиная с иконкой не топ совместив с изображением. Кроме того, я бы хотел, чтобы имя пользователя было сосредоточено относительно значка.

Наконец, я хочу, чтобы последняя строка была выровнена с нижней частью изображения слева.

Я начал использовать layout_weight, и я не мог заставить его работать. Поэтому я применил жесткую ширину и высоту.

В идеале, я бы хотел, чтобы первый ImageView занимал 30% строки. Значок будет занимать 7%, а остальные будут выделены для текстового просмотра в первой строке.

Спасибо за ваши предложения.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/custom_shape" 
       > 

    <ImageView 
     android:id="@+id/imgVideo" 
     android:src="@drawable/video_default_preview" 
     android:layout_width = "150dp" 
     android:layout_height= "150dp" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp"/> 

    <ImageView 
     android:id="@+id/imgOwner" 
     android:layout_width = "35dp" 
     android:layout_height= "35dp" 
     android:src="@drawable/icon_default_avator" 
     android:layout_marginBottom="10dp" 
     android:layout_alignTop="@+id/imgVideo" 
     android:layout_marginRight="10dp" 
     android:layout_toRightOf="@id/imgVideo"/> 

    <TextView 
     android:id="@+id/txtUserName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Plus" 
     android:layout_marginBottom="10dp" 
     android:layout_toRightOf="@id/imgOwner"/> 

    <TextView 
     android:id="@+id/txtVideoTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Mercedes SL 55" 
     android:textSize="10sp" 
     android:layout_marginBottom="10dp" 
     android:layout_alignLeft="@+id/imgOwner" 
     android:layout_below="@id/imgOwner"/> 

    <TextView 
     android:id="@+id/txtVideoName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="European Car ..." 
     android:textSize="10sp" 
     android:layout_alignLeft="@+id/txtVideoTitle" 
     android:layout_below="@+id/txtVideoTitle" 
     /> 
</RelativeLayout> 

ответ

2

Я изменил ваш xml, как вы описали.

В идеале, я бы хотел, чтобы первый ImageView занимал 30% строки . Значок будет занимать 7%, а остальное будет выделено текстовому представлению в первой строке.

Для этого вы должны использовать linearlayouts с весом attr. (30% для первого изображения, 70% для других. И 7% 70% 's, которая равна 10% внутренней значок)

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

    <ImageView 
     android:id="@+id/imgVideo" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_weight="3" 
     android:scaleType="centerInside" 
     android:src="@drawable/ic_launcher" /> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="7" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_vertical" 
      android:orientation="horizontal" > 

      <ImageView 
       android:id="@+id/imgOwner" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:scaleType="centerInside" 
       android:src="@drawable/ic_launcher" /> 

      <TextView 
       android:id="@+id/txtVideoTitle" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="10" 
       android:text="Mercedes SL 55" 
       android:textSize="10sp" /> 
     </LinearLayout> 

     <TextView 
      android:id="@+id/txtVideoName" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="European Car ..." 
      android:textSize="10sp" /> 

     <TextView 
      android:id="@+id/txtUserName" 
      android:layout_width="wrap_content" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:text="Plus" /> 
    </LinearLayout> 

</LinearLayout> 
0
// try this 
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="wrap_content" 
    android:padding="5dp" 
    android:layout_width="match_parent"> 

    <ImageView 
     android:layout_height="150dp" 
     android:layout_width="150dp" 
     android:src="@drawable/ic_launcher" 
     android:adjustViewBounds="true" 
     android:scaleType="fitXY"/> 

    <LinearLayout 
     android:layout_height="match_parent" 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_marginLeft="5dp" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      android:gravity="center_vertical"> 

      <ImageView 
       android:layout_height="35dp" 
       android:layout_width="35dp" 
       android:src="@drawable/ic_launcher" 
       android:adjustViewBounds="true" 
       android:scaleType="fitXY"/> 

      <TextView 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:textSize="10sp" 
       android:layout_marginLeft="5dp" 
       android:text="Plus"/> 
     </LinearLayout> 

     <TextView 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:textSize="10sp" 
      android:layout_marginTop="5dp" 
      android:text="Mercedes SL 55"/> 

     <TextView 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:textSize="10sp" 
      android:layout_marginTop="5dp" 
      android:text="European Car ..."/> 

    </LinearLayout> 
</LinearLayout>