【问题标题】:Android: ListView background color when not enough items fill. [Screenshot]Android:当没有足够的项目填充时,ListView 背景颜色。 [截屏]
【发布时间】:2014-04-09 08:54:14
【问题描述】:

所以我有一个 ListView。这些项目有自己的可绘制对象。

分隔线也是它自己的可绘制对象。

现在,当我有一个 ListView 时,如下面的屏幕截图所示,没有足够元素填充的空白区域,它只是白色。

我已经尝试设置缓存颜色提示,但这并没有解决它(老实说想不出任何其他可能有问题的地方)。

感谢任何帮助。

添加一些代码...

我的 ListView 创建和属性:

    final ListView v = new ListView(this.getActivity());
    fl.setBackgroundColor(Color.TRANSPARENT);
    v.setBackgroundDrawable(this.getActivity().getResources().getDrawable(R.drawable.item_selector_bad));
    v.setDivider(new ColorDrawable(Color.parseColor("#00000000")));
    v.setDivider(this.getActivity().getResources().getDrawable(R.drawable.item_square));
    v.setCacheColorHint(Color.TRANSPARENT);
    v.setSelector(this.getActivity().getResources().getDrawable(R.drawable.item_selector_bad));
    v.setDividerHeight(20);

至于xml文件,大体布局是这样的

列表中的一项具有:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@drawable/item_square">
    </item>
    <item android:drawable="@drawable/item_green">
    </item>
</layer-list>

item_square 只是:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/light_grid"
    android:tileMode="repeat" >

</bitmap>

item_green:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="@color/light_green" />


    <corners
        android:bottomLeftRadius="25dp"
        android:bottomRightRadius="25dp"
        android:topLeftRadius="25dp"
        android:topRightRadius="25dp" />

</shape>

【问题讨论】:

  • 请注意...导航栏上方的白色区域就是我的意思(那个或中包条目下方的位置)。
  • 请发布您的布局文件。
  • 在列表视图中定义布局。您是否尝试添加 android:background="#00000000".
  • 我已经编辑了问题以包含一些来源。 @LiemVo,我已经这样做了,但是没有任何改变。
  • 如何设置列表视图的背景颜色?

标签: android listview background drawable


【解决方案1】:

所以,我想到了这个解决方案,但是,我读到它对性能有影响。我想这还不错,如果是,我一定会重新发布并添加赏金。但是,您基本上只是让 ListView 使用包装内容作为高度。

White Space around List View Items

他们还有很多类似的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-10
    • 2016-03-13
    • 2011-09-19
    • 1970-01-01
    • 2011-01-14
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    相关资源
    最近更新 更多