【问题标题】:Android listview backgroundAndroid列表视图背景
【发布时间】:2015-07-04 09:49:01
【问题描述】:

我正在为 Android 实现这样的列表视图。

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

<?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,它位于可绘制文件夹中。

我已尝试将其设置为列表视图的背景

<?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>

但是列表视图没有改变以反映新的背景。有什么问题吗?

【问题讨论】:

  • AndroidStudio 编辑器中的列表视图,还是您启动时手机中的列表视图?
  • Android Studio 中的 Android 模拟器

标签: android listview


【解决方案1】:

您应该将相对布局的背景设置为具有半径的可绘制对象。不知道你是怎么命名的

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/bakcground_with_radius" >
   ...
</RelativeLayout>

【讨论】:

【解决方案2】:

对于列表视图,您将其设置为分隔线而不是背景。检查并纠正它

【讨论】:

  • 是的。我刚刚意识到并纠正了它。现在它运行良好。无论如何感谢您的回答。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-17
  • 1970-01-01
  • 2012-12-13
  • 1970-01-01
  • 1970-01-01
  • 2011-12-17
相关资源
最近更新 更多