【问题标题】:How to set divider properties in a listFragment?如何在 listFragment 中设置分隔符属性?
【发布时间】: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 更改为其他内容会导致崩溃。

【问题讨论】:

    标签: android android-fragments


    【解决方案1】:

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

    android:dividerHeight="1dip"
    

    【讨论】:

      【解决方案2】:

      您应该通过以下方式在列表视图项中设置分隔线颜色:

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

      例如。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-11-17
        • 2011-07-16
        • 2016-01-16
        • 2016-10-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多