2015-02-06 72 views
0

我需要使一行的列表視圖如下所示: 該行由三列組成,左側必須包含具有背景顏色的佈局中間和右側的文字與圖像相同。中間佈局將包含三行文本 我需要兩側佈局具有固定寬度,中間佈局的寬度取決於設備分辨率。Android兩個固定寬度的佈局和一箇中間有液體寬度的佈局

實施例:https://www.dropbox.com/s/udn1lfo1hy6px44/Captura%20de%20pantalla%202015-02-06%20a%20las%201.png?dl=0

我的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="match_parent"> 

    <RelativeLayout 
     android:id="@+id/lytVoterNumber" 
     android:layout_width="75dp" 
     android:layout_height="match_parent" 
     android:background="@android:color/holo_red_dark" 
     android:layout_alignParentLeft="true"> 

     <TextView 
      android:id="@+id/lblVoterNumber" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="1999" 
      android:layout_centerVertical="true" 
      android:layout_centerHorizontal="true" 
      /> 
    </RelativeLayout> 

    <LinearLayout 
     android:id="@+id/lytVoterData" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentTop="true" 
     android:layout_toEndOf="@+id/lytVoterNumber" 
     android:layout_toRightOf="@+id/lytVoterNumber"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Text Text Text" 
      android:id="@+id/lblVoterLastName" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Text Text Text" 
      android:id="@+id/lblVoterName" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Text Text Text" 
      android:id="@+id/lblDni" /> 
    </LinearLayout> 

    <RelativeLayout 
     android:layout_width="100dp" 
     android:layout_height="match_parent" 
     android:background="@android:color/holo_blue_dark" 
     android:id="@+id/lytIcono" 
     android:layout_alignParentRight="true" 
     android:minHeight="30dp" 
     android:minWidth="30dp" 
     android:nestedScrollingEnabled="false"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/imageView" 
      android:layout_centerVertical="true" 
      android:layout_centerHorizontal="true" 
      android:src="@drawable/flecha"/> 
    </RelativeLayout> 
</RelativeLayout> 
+2

那麼,你面臨什麼問題? – iRuth 2015-02-06 01:21:33

+0

對你有幫助嗎? – Elltz 2015-02-09 17:31:37

+0

是的,它的工作原理!謝謝!。 – jamarfal 2015-02-10 16:15:18

回答

3

檢查此

<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
android:weightSum="10" > 

這是LinearLayoutorientation水平並且它具有的一個weight sum現在所有你所要做的就是分裂到,使兩側Views具有的,其餘相同比例將中間的傢伙的比例,因此對於例如,如果你想有一個TextView作爲一個孩子這linearLayout的給TextView0dp一個width和1 weight,同樣與其他權利View,同樣weight相同width然後8/10去留下,所以屏幕大小的8/10是你中間View

所以你的整體會看起來這樣

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:weightSum="10" > 

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

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="8" 
    android:text="Large Text" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

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

得到它,先生?