【发布时间】:2014-02-27 10:31:40
【问题描述】:
我正在尝试将侧边栏图像添加到 ListView 中的某些项目。 图像应占据项目的整个高度,并在必要时垂直重复。 拉伸图像不是一种选择。
在尝试了几件事后,我最终修改了找到here 的代码。 不幸的是,它似乎在 ListView 中不起作用,并且图像不会重复:
主布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
ListView 项目布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical">
<ImageView
android:id="@+id/listitem_sidebar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/sidebar"
android:visibility="invisible"/>
</LinearLayout>
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="400dp"
android:text="Test"
android:layout_alignParentRight="true"/>
</RelativeLayout>
背景可绘制:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/sidebar"
android:tileMode="repeat" />
背景图片:
为整个 ListView 全局设置侧边栏不是一个选项,因为我在生产代码中为项目使用不同的视图类型。
编辑:格式化
【问题讨论】:
标签: android listview background bitmap tile