简体   繁体   中英

Android ListView background image optimisation

I've run into a problem, the problem is that I have a ListView and I want to set a background image on that ListView . I managed to achieve this using the background attribute in XML and set the cacheColorHint to #00000000 .

If I make the cacheColorHint to transparent color like above, the scrolling performance drops significantly. On Android smartphones my ListView is working good but on Android Tablet the ListView is moving very slow.

The image I use as a Drawable has the size about 500x800px (the one for Tablets), the one for phones is smaller. Iv'e tried also to set a smaller image(like the one for phones) but it's the same.

My image has only a logo at the bottom of the screen having about 100px height and the rest is a white color.

Does anybody know how I can make the ListView work properly or at least better?

Thank you!

I managed to optimize the speed of the ListView by cutting the white color off and setting the logo image onto a ImageView.

Here is my XML now:

<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"/>

Her is what you are looking to implement:

LayerDrawable- A Drawable that manages an array of other Drawables. These are drawn in array order, so the element with the largest index will be drawn on top.

OR

use Frame layout to achieve desired affect. http://tinyurl.com/82ycrpd

Unfortunately, aside from the obvious solution of not using an image as the background, you've done everything you can to optimize the ListView . One thing you could try is to set the cacheColorHint to the most dominant color in the image.

What I mean by that is, looking at the book example from the previous link, you could set the cacheColorHint color to some sort of an orange which would result in your scrolling operations being a lot less expensive, compared to when set to transparent ( #00000000 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM