【问题标题】:Why divider is not showing in the listview @android:id/list ?为什么分隔线没有显示在列表视图 @android:id/list 中?
【发布时间】:2012-03-16 16:20:15
【问题描述】:

我有一个包含以下列表视图的线性布局:

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:cacheColorHint="#00000000"
    android:divider="#FF0000"
    android:dividerHeight="4dp"
     />

并且布局被ListActivity使用,问题是ListView xml中的以下行没有生效:

     android:divider="#FF0000"
    android:dividerHeight="4dp"

并设置了默认分隔符。你为什么会发生这种情况以及如何解决它?

【问题讨论】:

  • 我检查了它,它适用于我和红色分隔线,,,,

标签: android listview listactivity


【解决方案1】:

dp 和 px 的区别。

使用这个

android:dividerHeight="4px"

而不是

android:dividerHeight="4dp"

如果你愿意也可以使用它

int[] colors = {0, 0xFFFF0000, 0}; // red for the example
myList.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
myList.setDividerHeight(1);

你会得到它..

【讨论】:

【解决方案2】:

对我来说这是完美的:

 <ListView
     android:id="@+id/listHomeScreen"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:cacheColorHint="#000"
     android:divider="#7F7F7F"
     android:dividerHeight="1dip"
     android:listSelector="@android:color/transparent" >
</ListView>

确保我们没有覆盖 android:dividerHeight 或分隔线颜色。

【讨论】:

    【解决方案3】:

    现在解决了。问题是在我决定在 xml 中创建列表之前,我在我的 listActivity 中有这段代码来添加覆盖 xml 的分隔符:

    int[] colors = { 0xA8A8A8A8, 0xFFFFFFFF, 0xA8A8A8A8 };
    getListView().setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
    getListView().setDividerHeight(1);
    

    【讨论】:

      【解决方案4】:

      如果您覆盖了 setEnabled(),Android Lollipop 5.0 中会出现错误,然后会发生这种情况。 查看此问题以获取更多信息 ListView divider not showing in Android 5

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-02-05
        • 2021-12-02
        • 2018-09-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多