如何在listFragment中设置分隔符属性



在我的应用程序中,我有一个FragmentActivity,它实现ListFragment.OnSelectedListener.

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更改为其他内容会导致崩溃。

您还可以使用以下代码更改列表分隔符的高度

android:dividerHeight="1dip"

您应该通过:在列表视图项中设置分隔符颜色

android:divider="@android:color/transparent"

例如。

最新更新