我有一个ListView
其中每一行都有以下
1。2 TextView
。Button
TextView
s 可以包含多种长度的文本。所以列表以一种尴尬的方式出现。我认为解决方法是将每个 List 项设置为具有 2 个单元格(TextView 和 Button)的表格行。有没有办法做到这一点?或者可能有更好的解决方案?
我有一个ListView
其中每一行都有以下
1。2 TextView
。Button
TextView
s 可以包含多种长度的文本。所以列表以一种尴尬的方式出现。我认为解决方法是将每个 List 项设置为具有 2 个单元格(TextView 和 Button)的表格行。有没有办法做到这一点?或者可能有更好的解决方案?
您可以使用相对布局来显示该行。在相对布局中,在右侧放置一个按钮,将 align parent right 为 true,然后将 TextView 设置为 Button 的左侧以匹配父级。您也可以将 TextView 指定为单行,最后将椭圆大小指定为 true。这只是一个例子
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:gravity="center_vertical"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Button" />
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:singleLine="true"
android:ellipsize="end"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_toLeftOf="@+id/button1"
android:text="This is your textView with a very long text. I hope this code serves your problem" />
</RelativeLayout>
您还可以使用 2 个 TextView,这完全取决于您要显示的文本。
LinearLayout 和它的权重属性。更多官方文档http://developer.android.com/guide/topics/ui/layout/linear.html