【发布时间】:2016-10-28 04:09:00
【问题描述】:
我有一个我想展示的项目列表。我写了以下代码
对于每个项目的视图:
<?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="wrap_content"
android:paddingEnd="12dp"
android:paddingStart="8dp"
android:paddingTop="4dp"
android:paddingBottom="4dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="6"
android:gravity="center" >
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="4">
<TextView
android:id="+@id/receipt_item_name"
android:layout_width="wrap_content"
android:textAlignment="viewStart"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="item name" />
<TextView
android:layout_width="wrap_content"
android:textAlignment="viewStart"
android:layout_height="wrap_content"
android:layout_below="@id/receipt_item_name"
android:text="selected by 2 others"
android:textSize="10sp"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAlignment="textEnd"
android:text="10$" />
</LinearLayout>
</RelativeLayout>
但是当receipt_item_name中的文本太长时,它会成为下一个
textview 右移。如何确保每个视图的权重可靠?
或者我还能做些什么来获得同样的效果?
【问题讨论】:
标签: android xml android-layout android-studio android-recyclerview