我遇到了一个问题,问题是我有一个ListView
,我想在该ListView
上设置背景图像。我设法使用XML
中的background
属性实现了这一点,并将cacheColorHint
设置为#00000000
。
如果我像上面那样将cacheColorHint
设置为透明颜色,则滚动性能会显著下降。在安卓智能手机上,我的ListView
运行良好,但在安卓平板电脑上,ListView
运行非常缓慢。
我用作Drawable
的图像大小约为500x800px(平板电脑的图像),手机的图像较小。Iv'e也尝试设置一个较小的图像(就像手机上的图像),但它是一样的。
我的图片在屏幕底部只有一个标志,大约有100px的height
,其余的都是白色。
有人知道我如何让ListView
正常工作或至少更好吗?
谢谢!
我设法优化了ListView的速度,去掉了白色,并将徽标图像设置到ImageView上。
现在是我的XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white">
<ImageView android:layout_width="fill_parent" android:layout_height="wrap_content" android:scaleType="fitXY"
android:src="@drawable/background_img" android:layout_alignParentBottom="true"/>
<ListView android:layout_width="fill_parent" android:layout_height="fill_parent"
android:drawSelectorOnTop="false" android:cacheColorHint="#00000000"
android:smoothScrollbar="true" android:scrollingCache="true"/>
不幸的是,除了使用图像作为背景的而不是的明显解决方案之外,您已经尽了一切努力来优化ListView
。您可以尝试将cacheColorHint
设置为图像中最主要的颜色。
我的意思是,看看上一个链接中的书示例,您可以将cacheColorHint
颜色设置为某种橙色,这将使您的滚动操作与设置为透明(#00000000
)时相比成本大大降低。
她就是您想要实现的:
图层可绘制-一个Drawable,用于管理一组其他Drawable。这些是按数组顺序绘制的,因此索引最大的元素将绘制在顶部。
或
使用框架布局来实现所需效果。http://tinyurl.com/82ycrpd