【问题标题】:Android ListView background image optimisationAndroid ListView 背景图片优化
【发布时间】:2012-01-05 18:18:40
【问题描述】:

我遇到了一个问题,问题是我有一个ListView,我想在那个ListView 上设置一个背景图像。我设法使用XML 中的background 属性实现了这一点,并将cacheColorHint 设置为#00000000

如果我像上面那样将cacheColorHint 设置为透明色,滚动性能会显着下降。在 Android 智能手机上,ListView 运行良好,但在 Android 平板电脑上,ListView 运行缓慢。

我用作Drawable 的图像大小约为 500x800 像素(用于平板电脑的图像),用于手机的图像较小。我也尝试设置一个较小的图像(如手机的图像),但它是一样的。

我的图像在屏幕底部只有一个徽标,大约 100 像素 height,其余为白色。

有人知道我怎样才能使ListView 正常工作或至少更好地工作吗?

谢谢!

【问题讨论】:

  • 通常我在布局中使用 ListView 并将背景添加到布局中并将 listview 背景和颜色提示设置为透明。
  • 我也这样做了,但没有结果..还是谢谢

标签: java android xml listview drawable


【解决方案1】:

我设法通过关闭白色并将徽标图像设置到 ImageView 上来优化 ListView 的速度。

这是我现在的 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"/>

【讨论】:

    【解决方案2】:

    不幸的是,除了使用图像作为背景的明显解决方案之外,您已经为optimizeListView 做了所有可以做的事情。您可以尝试的一件事是将cacheColorHint 设置为图像中最主导的颜色。

    我的意思是,查看上一个链接中的 book 示例,您可以将 cacheColorHint 颜色设置为某种橙色,这将导致您的滚动操作为 #00000000) 相比,em>便宜很多。

    【讨论】:

    • 感谢您的提示。我也阅读了该页面,但我希望也许有人设法解决问题..
    【解决方案3】:

    她就是你想要实现的:

    LayerDrawable- 管理其他 Drawable 数组的 Drawable。这些是按数组顺序绘制的,因此索引最大的元素将被绘制在顶部。

    使用框架布局来实现所需的效果。 http://tinyurl.com/82ycrpd

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多