也有类似的问题,但我还没有看到一个答案这个非常直接的问题:你如何设置一个自定义列表视图混合的布局?Android:使用删除按钮设置ListView
我试图建立一个列表视图,其中每一行有以下几点:
初级文本行,二次的(子)文本行,和删除按钮。另一种方法是让每行在可见空间的页眉或页脚处使用删除按钮进行选择(但显然不在可滚动空间中)。说实话,在这一点上更容易一些是可取的。
我剩下的就是设置一个辅助布局xml来定义每一行元素,但在里面我正在寻找另一个布局来将按钮与文本布局的垂直方向分开。
这里是我当前的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:choiceMode="multipleChoice"
android:id="@+id/android:list"/>
</LinearLayout>
每一行的布局是这样的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="@+id/line_a"
android:textSize="14dp"
android:textColor="#FFFFFF"
android:textStyle="italic"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/line_b"
android:textSize="12dp"
android:textColor="#BFFF00"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
这个选项可以设置每行一个不错的多色两级文本在ListView 。
那么接下来呢?要在右侧添加一个按钮,我需要使用右侧的按钮来设置另一个布局(网格可能是?2列1行?)。另一种替代方法就像是用水平方向在另一个线性布局中包裹现有的垂直线性布局,是的?
难道这不会让任何人感到尴尬和痛苦吗? :)
这就是答案。 – 2013-04-09 21:37:41
谢谢阿里。我假设我膨胀的“list_item”布局对应于我上面共享的行布局? – Raevik 2013-04-10 13:02:47