TextView and RelativeLayout onMeasure called a lot

  • Replies:1
Bob Loblaw
  • Forum posts: 1

Jun 5, 2012, 12:53:31 AM via Website

I'm using traceview in attempts to optimize my code. I noticed that TextView.onMeasure() and RelativeLayout.onMeasure() gets called a lot, and I'm trying to see if there is any way I can optimize this. In my ListAdapter, I'm already using ViewHolders, checking if currentView is null as suggested by various google talks/Romain Guy. Here is a screenshot of my costly functions in traceview.

Below is code for my layout in the list, to prove that it's not crazy complicated.

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="178dp"
android:background="@color/Transparent"
android:clickable="true" >
<RelativeLayout
android:id="@+id/Holder"
android:layout_width="147dp"
android:layout_height="178dp"
android:layout_centerInParent="true"
android:background="@color/Transparent" >
<ImageView
android:id="@+id/userIcon"
android:layout_width="141dp"
android:layout_height="141dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="1dp"
android:background="@color/Transparent" />
<RelativeLayout
android:id="@+id/userInfoSection"
android:layout_width="143dp"
android:layout_height="35dp"
android:layout_below="@id/userIcon"
android:layout_centerHorizontal="true"
android:background="@color/Black" >
<Button
android:id="@+id/MenuButton"
android:layout_width="31dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:scaleType="fitCenter"
android:src="@drawable/btn_menu" />
<TextView
android:id="@+id/Name"
android:layout_width="100dp"
android:layout_height="17dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="3dp"
android:layout_toLeftOf="@id/MenuButton"
android:singleLine="true"
android:ellipsize="end"/>
<TextView
android:id="@+id/Age"
android:layout_width="39dp"
android:layout_height="14dp"
android:layout_below="@id/Name"
android:layout_marginRight="20dp"
android:layout_toLeftOf="@id/MenuButton"
android:singleLine="true"
android:ellipsize="end"
style="@style/Text.Default" />
<TextView
android:id="@+id/Location"
android:layout_width="30dp"
android:layout_height="14dp"
android:layout_below="@id/Name"
android:layout_alignParentLeft="true"
android:layout_marginLeft="3dp"
android:layout_toLeftOf="@id/Price"
android:singleLine="true"
android:ellipsize="end"
style="@style/Text.Default" />
</RelativeLayout>
</RelativeLayout>
<ImageView
android:id="@+id/loading_indicator"
android:contentDescription="@string/imageView_caption_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="115dp"
android:layout_marginTop="5dp"
android:src="@drawable/loading_indicator"
android:visibility="gone" />
</RelativeLayout>
Any help would be appreciated, thanks.

Reply
Eric McBride
  • Forum posts: 1,790

Jun 5, 2012, 2:21:42 PM via Website

Jeremiah is our coding God around here. Hopefully he can help.

@Jeremiah, you around to help out on this one? :)

Reply