jam*_*fal 2 layout android android-layout
我需要在列表视图中创建一行:该行由三列组成,左侧必须包含一个布局,背景颜色和文本位于中心,右侧相同但带有图像。中间布局将包含三行文本我需要两侧布局具有固定宽度,中间布局具有取决于设备分辨率的宽度。
示例: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>
Run Code Online (Sandbox Code Playgroud)
检查这个
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="10" >
Run Code Online (Sandbox Code Playgroud)
这是一个LinearLayout
有orientation
水平的,它有一个weight sum
的10现在你需要做的是分裂10到3,使两侧Views
有相同比例的10,剩下的将是中间的家伙的比例,因此对于例如,如果您想TextView
为这个孩子linearLayout
给TextView
一个width
的0dp和weight
1,也是一样与其他权利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" />
Run Code Online (Sandbox Code Playgroud)
明白了吗,先生?