我想使用空视图来指示ListView中每个项目的颜色。Android查看背景布局问题
这个想法是,rowColor View只是一个3dp宽线,应该自动调整大小到secondLine和thirdLine的高度(请注意,所有内容都是在代码中设置的,包括rowColor的背景色以及firstLine和thirdLine通常设置为GONE)。
它在Eclipse的图形布局中显示得很完美,但rowColor根本不显示在我的手机上(运行2.3.3)并且所有视图都堆叠在一起。任何想法如何解决它?
以下代码为list_row从here采用。我已经提供了所有我认为基于该布局工作的代码,但并未完全关闭。这种布局是否仍然有效?
list_row.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<TextView
android:id="@+id/firstLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:singleLine="true"
android:text="First Line" />
<View
android:id="@+id/rowColor"
android:background="#FF0000"
android:layout_width="3dp"
android:layout_height="fill_parent"
android:layout_below="@id/firstLine"
android:layout_alignParentBottom="true" />
<TextView
android:id="@+id/thirdLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/rowColor"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:singleLine="true"
android:text="Third Line" />
<TextView
android:id="@+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/rowColor"
android:layout_alignParentRight="true"
android:layout_below="@id/firstLine"
android:layout_above="@id/thirdLine"
android:layout_alignWithParentIfMissing="true"
android:gravity="center_vertical"
android:singleLine="true"
android:text="Second Line" />
</RelativeLayout>
的main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
ListViewTest.java活动在这里:http://pastie.org/2035822
感谢。
也许尝试“wrap_content”,看看是什么 – Austin 2011-06-08 01:00:04
它显示过吗?还是只有当firstList是GONE时才会失踪 – jkhouw1 2011-06-08 01:15:22
好吧rowColor从来没有内容,只是背景颜色。它不会显示为wrap_content或match_parent,或firstLine为GONE时。当我将它的高度设置为40dp时,我只会看到它。 – kevin 2011-06-08 01:22:04