【发布时间】:2012-04-02 17:32:32
【问题描述】:
在我的应用中,我有一个实现 ListFragment.OnSelectedListener 的 FragmentActivity。
ListFragment 使用了一个自定义适配器,它扩展了 customrow.xml 布局。
我想更改列表中的分隔线颜色和高度。
我想我需要使用 android:divider 属性,但不知道具体如何。
我尝试将它放在 FragmentActivity 的布局和 customrow.xml 布局中,但它不起作用...
customrow.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="@drawable/item_selector"
android:divider="#f19000" >
...textview and imageview...
</LinearLayout>
编辑:解决方案
感谢大家的帮助! 问题是我没有为我的 ListFragment 扩展自定义 xml...
因此,创建一个新的 list_fragment.xml 并在我的 ListFragment 中添加类似的内容就可以了:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.list_fragment, null);
return view;
}
list_fragment.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:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#f19000"
android:dividerHeight="1dip" >
</ListView>
</LinearLayout>
此外,android:id="@android:id/list" 是强制性的,将 id 更改为其他内容会导致崩溃。
【问题讨论】: