Android ListView 背景

标签 android listview

我正在为 Android 实现这样的 ListView 。

beautiful list view

不用担心选择器和每个项目左侧的细条,列表项的可绘制背景布局将是:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <stroke android:width="1dp" android:color="#000000" />
    <corners
        android:bottomRightRadius="27dp"
        android:topRightRadius="27dp" />
</shape>

我将其命名为 list_border.xml,它位于可绘制文件夹中。

我尝试将其设置为 ListView 的背景

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/list_padding"
    android:paddingRight="@dimen/list_padding"
    android:divider="@drawable/list_border"/>

并作为每个列表项的背景

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:divider="@drawable/list_border" >

    <ImageView
        android:id="@+id/menu_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/arrow1_e" />

    <org.bitbucket.infovillafoundation.denko.customui.MyanmarTextView
        android:id="@+id/menu_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/menu_icon" />
</RelativeLayout>

但是 ListView 没有改变以反射(reflect)新的背景。有什么问题吗?

最佳答案

对于 ListView ,您将其设置为分隔符而不是背景。检查并改正

关于Android ListView 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29870379/

相关文章:

android设置列表项自定义背景色

javascript - React-native formik 表单引用始终为空

java - android.view.InflateException : Binary XML file line #0: Binary XML file line #0: Error inflating class <Classname>

android - 点击文字打开图片

c# - 获取被点击的ListView项目属性

android - arrayAdapter 中的 getItem() 如何工作?

C# Windows 通用应用程序 ListView 所选项目内容

java - 如何制作更适合的fragment

android - .xml 文件中的 android 和 android2 字段有什么区别?

android - 如何在 ListView 滚动时禁用或更改黑行的颜色