Monday, August 22, 2011

[android-developers] ListView measurering causes constant getView(..) requests, slowing down the device

The issue described here was encountered on 3.0 as well as 3.1 on an
Acer Iconia A500. The following layout is used in a Fragment (not
ListFragment). Somehow it causes a ListView, added to
fragment_swipeview_lr_leftview_body (and
fragment_swipeview_lr_rightview_body respectively), to be measured
over and over again, thus refreshing its content more often then
required and hence significantly slowing down the device.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/fragment_swipeview_lr_mainlayout">
<RelativeLayout android:id="@+id/fragment_swipeview_lr_leftview"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_marginRight="5dip">
<RelativeLayout android:layout_height="wrap_content"
android:id="@+id/fragment_swipeview_lr_leftview_header"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@drawable/
fragment_swipeview_header_background_left"
android:layout_width="wrap_content" android:layout_alignLeft="@+id/
fragment_swipeview_lr_leftview_body"
android:layout_alignRight="@+id/
fragment_swipeview_lr_leftview_body">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/
fragment_swipeview_vt_leftview_headertext"
android:text="Left Heading" android:textAppearance="@style/
style_text_swipeview_header"
android:layout_marginLeft="10dip"></TextView>
</RelativeLayout>
<RelativeLayout android:background="@drawable/
fragment_swipeview_body_background_left"
android:layout_height="fill_parent" android:layout_below="@id/
fragment_swipeview_lr_leftview_header"
android:layout_width="wrap_content" android:id="@+id/
fragment_swipeview_lr_leftview_body"></RelativeLayout>
</RelativeLayout>
<RelativeLayout android:layout_height="fill_parent"
android:layout_toRightOf="@+id/fragment_swipeview_lr_leftview"
android:layout_width="wrap_content" android:id="@+id/
fragment_swipeview_lr_rightview">
<RelativeLayout android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="@+id/
fragment_swipeview_lr_header_body_wrapper"
android:layout_toRightOf="@+id/
fragment_swipeview_vi_rightview_shadow">
<RelativeLayout android:layout_alignLeft="@+id/
fragment_swipeview_lr_rightview_body"
android:layout_alignRight="@+id/
fragment_swipeview_lr_rightview_body"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:id="@+id/fragment_swipeview_lr_rightview_header"
android:background="@drawable/
fragment_swipeview_header_background_right">
<TextView android:text="Right Heading"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip" android:textAppearance="@style/
style_text_swipeview_header"
android:layout_width="wrap_content" android:id="@+id/
fragment_swipeview_vt_rightview_headertext"></TextView>
</RelativeLayout>
<RelativeLayout android:layout_height="fill_parent"
android:layout_width="wrap_content" android:layout_below="@+id/
fragment_swipeview_lr_rightview_header"
android:id="@+id/fragment_swipeview_lr_rightview_body"
android:background="@drawable/
fragment_swipeview_body_background_right"></RelativeLayout>
</RelativeLayout>
<ImageView android:background="@drawable/general_shadow_left"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:id="@+id/fragment_swipeview_vi_rightview_shadow"
android:visibility="gone"></ImageView>
</RelativeLayout>
</RelativeLayout>

The ListView is added using the following code (tried using explicit
LayoutParameters as well).

public void addViewToLeftContentLayout(View v) {
leftContent.addView(v); // leftcontent ==
fragment_swipeview_lr_leftview_body
}

Here is the stacktrace representing individual measurement updates:

AdapterIngredientList.getView(int, View, ViewGroup) line: 43
ListView(AbsListView).obtainView(int, boolean[]) line: 1970
ListView.measureHeightOfChildren(int, int, int, int, int) line: 1228
ListView.onMeasure(int, int) line: 1139
ListView(View).measure(int, int) line: 10828
RelativeLayout.measureChild(View, RelativeLayout$LayoutParams, int,
int) line: 566
RelativeLayout.onMeasure(int, int) line: 381
RelativeLayout(View).measure(int, int) line: 10828
RelativeLayout.measureChildHorizontal(View, RelativeLayout
$LayoutParams, int, int) line: 581
RelativeLayout.onMeasure(int, int) line: 365
RelativeLayout(View).measure(int, int) line: 10828
RelativeLayout.measureChildHorizontal(View, RelativeLayout
$LayoutParams, int, int) line: 581
RelativeLayout.onMeasure(int, int) line: 365
RelativeLayout(View).measure(int, int) line: 10828
RelativeLayout.measureChildHorizontal(View, RelativeLayout
$LayoutParams, int, int) line: 581
RelativeLayout.onMeasure(int, int) line: 365
RelativeLayout(View).measure(int, int) line: 10828
RelativeLayout.measureChildHorizontal(View, RelativeLayout
$LayoutParams, int, int) line: 581
RelativeLayout.onMeasure(int, int) line: 365
RelativeLayout(View).measure(int, int) line: 10828
RelativeLayout.measureChildHorizontal(View, RelativeLayout
$LayoutParams, int, int) line: 581
RelativeLayout.onMeasure(int, int) line: 365
RelativeLayout(View).measure(int, int) line: 10828
RelativeLayout.measureChildHorizontal(View, RelativeLayout
$LayoutParams, int, int) line: 581
RelativeLayout.onMeasure(int, int) line: 365
RelativeLayout(View).measure(int, int) line: 10828
RelativeLayout.measureChildHorizontal(View, RelativeLayout
$LayoutParams, int, int) line: 581
RelativeLayout.onMeasure(int, int) line: 365
RelativeLayout(View).measure(int, int) line: 10828
RelativeLayout.measureChildHorizontal(View, RelativeLayout
$LayoutParams, int, int) line: 581
RelativeLayout.onMeasure(int, int) line: 365
RelativeLayout(View).measure(int, int) line: 10828
RelativeLayout.measureChildHorizontal(View, RelativeLayout
$LayoutParams, int, int) line: 581
RelativeLayout.onMeasure(int, int) line: 365
RelativeLayout(View).measure(int, int) line: 10828
LinearLayout(ViewGroup).measureChildWithMargins(View, int, int, int,
int) line: 4351
LinearLayout.measureChildBeforeLayout(View, int, int, int, int, int)
line: 1284
LinearLayout.measureVertical(int, int) line: 613
LinearLayout.onMeasure(int, int) line: 519
LinearLayout(View).measure(int, int) line: 10828
FrameLayout(ViewGroup).measureChildWithMargins(View, int, int, int,
int) line: 4351
FrameLayout.onMeasure(int, int) line: 267
FrameLayout(View).measure(int, int) line: 10828
LinearLayout.measureVertical(int, int) line: 764
LinearLayout.onMeasure(int, int) line: 519
LinearLayout(View).measure(int, int) line: 10828
PhoneWindow$DecorView(ViewGroup).measureChildWithMargins(View, int,
int, int, int) line: 4351
PhoneWindow$DecorView(FrameLayout).onMeasure(int, int) line: 267
PhoneWindow$DecorView.onMeasure(int, int) line: 1908
PhoneWindow$DecorView(View).measure(int, int) line: 10828
ViewRoot.performTraversals() line: 909
ViewRoot.handleMessage(Message) line: 2003
ViewRoot(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 132
ActivityThread.main(String[]) line: 4026
Method.invokeNative(Object, Object[], Class, Class[], Class, int,
boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 491
ZygoteInit$MethodAndArgsCaller.run() line: 841
ZygoteInit.main(String[]) line: 599
NativeStart.main(String[]) line: not available [native method]

any suggestions / workarounds would be appreciated.

regards Patrick

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment