2011-02-28 106 views
4

我想有一个图像作为listview的背景。 每个项目都没有人,但是对于所有人来说,并且不会随着列表视图的移动而移动。 我该怎么做?ListView与背景图像

回答

13

我会做这样的事情:

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:src="@drawable/the_background_image"/> 
    <ListView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:cacheColorHint="#00000000"/> 
</RelativeLayout> 
+0

我尝试给顶部元素一个背景,但它只是没有正常工作。这做了魅力。谢谢 – Warpzit 2011-11-21 11:41:07

1

我已经使用这个:

<ListView 
    android:id="@android:id/list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@id/lists_header" 
    android:layout_marginLeft="6dip" 
    android:layout_marginRight="6dip" 
    android:divider="@drawable/list_divider" 
    android:dividerHeight="2dip" 
    android:cacheColorHint="@color/shopper_background" 
    android:background="@drawable/paper_frame" /> 

凡paper_frame是9.patch绘制。

这提供了一个(拉伸以填充ListView区域)固定的背景图像,不会随列表一起滚动,而可能是您正在尝试执行的操作。

我想要图像拉伸到列表的高度(即如果列表很长,顶部和/或底部可以离开屏幕),并且正在寻找如何做到这一点。