I am trying to create a list of people using Listview/customadapter. The rows show up pretty fast but scrolling is very slow even on a reasonably fast device. I tried several suggestions except using asynchtask hoping to have that as a last resort but nothing seems to improve the performance. Finally as a last shot before using asynchtask i tried to remove all processing in the adapter's getview method. Now all it does is inflate the view from an xml and display blank rows. I noticed that even then the scrolling speed hasnt improved. So i suspect the cause might be the structure of my layout. Is there any change i can do in it to make it faster ? Any help would be appreciated. Thanks in advance.
<TextView android:id="@+id/mId" android:text="TextView"
android:layout_width="0px" android:layout_height="0px"></TextView>
<TextView android:id="@+id/phone" android:layout_height="0px"
android:layout_width="0px"></TextView>
<TextView android:id="@+id/email" android:layout_height="0px"
android:layout_width="0px"></TextView>
<ImageView android:id="@+id/imageView1" android:layout_width="match_parent"
android:layout_height="110dp" android:adjustViewBounds="true"
android:scaleType="fitXY" android:src="@drawable/bl_row_bg"></ImageView>
<TextView android:paddingTop="9.7dp" android:id="@+id/name"
android:paddingLeft="25.88dp" android:text="xxxx"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textColor="@android:color/black" android:lines="1"
android:ellipsize="end" android:textStyle="bold"></TextView>
<ImageView android:src="@drawable/default_avatar" android:id="@+id/image1"
android:layout_height="110dp" android:layout_width="110dp"
android:scaleType="fitXY" android:paddingTop="6.47dp"
android:paddingBottom="6.47dp" android:paddingRight="6.47dp"
android:layout_alignParentRight="true"></ImageView>
<TextView android:id="@+id/txt1" android:paddingLeft="25.88dp"
android:text="Turning 24" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_below="@+id/name"
android:textColor="@android:color/black"></TextView>
<TextView android:id="@+id/txt2" android:paddingLeft="25.88dp"
android:text="23 Days to go" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_below="@+id/txt1"
android:textColor="@android:color/black"></TextView>
<ImageView android:layout_height="64.7dp" android:src="@drawable/ss_image2"
android:id="@+id/image2" android:layout_width="64.7dp"
android:scaleType="fitEnd" android:layout_alignBottom="@+id/imageView1"
android:layout_alignParentRight="true"></ImageView>
<ImageView android:src="@drawable/bl_date_background"
android:id="@+id/datebg" android:layout_height="110dp"
android:layout_width="25dp"></ImageView>
<ImageView android:id="@+id/icon1"
android:layout_toRightOf="@+id/datebg" android:layout_height="30dp"
android:layout_width="30dp" android:layout_alignBottom="@+id/imageView1"></ImageView>
<ImageView android:id="@+id/icon2"
android:layout_toRightOf="@+id/icon1" android:layout_height="30dp"
android:layout_width="30dp" android:layout_alignBottom="@+id/imageView1"></ImageView>
<ImageView android:id="@+id/icon3"
android:layout_toRightOf="@+id/icon2" android:layout_height="30dp"
android:layout_width="30dp" android:layout_alignBottom="@+id/imageView1"></ImageView>
<ImageView android:id="@+id/icon4" android:layout_toRightOf="@+id/icon3"
android:layout_height="30dp" android:layout_width="30dp"
android:layout_alignBottom="@+id/imageView1"></ImageView>
<ImageView android:id="@+id/icon5"
android:layout_toRightOf="@+id/icon4" android:layout_height="30dp"
android:layout_width="30dp" android:layout_alignBottom="@+id/imageView1"></ImageView>
<TextView android:id="@+id/date" android:text="Tue, Dec 12"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_alignParentLeft="true" android:textColor="@android:color/black"
android:textStyle="bold" android:gravity="center" android:visibility="invisible"></TextView>
Try following
ListView lv = getListView();
lv.setCacheColorHint(Color.TRANSPARENT); // not sure if this is required for you.
lv.setFastScrollEnabled(true);
lv.setScrollingCacheEnabled(false);
Make sure you consult the actual Android documentation first and compare the Java methods with the Android XML attributes:
http://developer.android.com/reference/android/widget/ListView.html
For those that need optimization in XML attributes:
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:cacheColorHint="@android:color/transparent"
android:fastScrollEnabled="true"
android:persistentDrawingCache="scrolling"
android:scrollingCache="false" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With