2015-02-06 75 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" /> 

得到它,先生?