Huge calls made to ViewRoot.draw()
I have an activity which has some text views and other data to be updated every second.
The performance is sluggish and when i capture the logs and view in TraceView. I see at lot of calls been made to ViewRoot.draw() function.
25 calls in a short span of 4 seconds, almost 6 calls every sec. Ideally speaking it should be once call every sec.
As per my initial speculation i beleive it is due to the bad layout of my xml, is this true?
How do i identify what is the reas开发者_StackOverflow社区on for so many calls? which is the best way to reduce these calls?
If these TextViews have their layout_width set to WRAP_CONTENT, then changing the text will trigger a measurement pass as their size will have changed. That could certainly get expensive. Try making them fixed-width.
Please find the layout below,
74 calls is ok but 25 calls are been made to ViewRoot.draw() in about 3.5 seconds which means 6 calls for draw every second that is bad.
I want to know why so many calls are made ?
<RelativeLayout
android:id="@+id/qd3"
android:layout_height="80px"
android:layout_width="156px"
android:layout_marginTop="4px"
android:layout_marginRight="2px"
android:layout_marginLeft="4px"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/qd2"
android:background="@drawable/btn_hl_vd_land"
android:clickable="true">
<FrameLayout
android:id="@+id/FrameCell3"
android:layout_height="wrap_content"
android:layout_width="wrap_content" >
<ImageView
android:id="@+id/qd3_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/qd_vd_gloss"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/gloss_wt_tr_land"
/>
</FrameLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/qd4"
android:layout_height="80px"
android:layout_width="156px"
android:layout_marginTop="4px"
android:layout_marginRight="2px"
android:layout_marginLeft="4px"
android:layout_below = "@+id/qd3"
android:layout_toRightOf="@+id/qd1"
android:background="@drawable/btn_hl_lp_land"
android:clickable="true"
>
<FrameLayout
android:id="@+id/FrameCell4"
android:layout_height="wrap_content"
android:layout_width="wrap_content" >
<ImageView android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_wt_lp_bg_land"></ImageView>
<ImageView android:id="@+id/ImageView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
></ImageView>
<ImageView android:id="@+id/ImageView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_wt_lp_num"></ImageView>
<ImageView
android:id="@+id/qd4_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/lpCountBig"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="50sp"
android:paddingTop="17px"
android:paddingLeft="65px"
/>
<TextView
android:id="@+id/lpCountSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="38sp"
android:paddingTop="22px"
android:paddingLeft="57px"
/>
</FrameLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/qd2"
android:layout_height="80px"
android:layout_width="156px"
android:layout_marginTop="4px"
android:layout_marginLeft="2px"
android:layout_toRightOf = "@+id/qd1"
android:layout_alignParentLeft="true"
android:background="@drawable/btn_hl_qd2_land"
android:clickable="true">
<FrameLayout
android:id="@+id/FrameCell4"
android:layout_height="wrap_content"
android:layout_width="wrap_content" >
<ImageView
android:id="@+id/qd_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/divider_wt_qd_land"
/>
<ImageView
android:id="@+id/qd_time_gloss"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/gloss_wt_tl_land"
/>
</FrameLayout>
<RelativeLayout
android:id="@+id/qd_time"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/mDataOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textColor="#000000"
android:textSize="44sp"
android:layout_alignParentRight="true"
android:paddingRight="8px"
android:paddingTop="2px"
/>
<TextView
android:id="@+id/mDataFive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textColor="#000000"
android:textSize="44sp"
android:layout_alignParentRight="true"
android:paddingRight="8px"
android:paddingTop="2px"
/>
<TextView
android:id="@+id/mDataSeven"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textColor="#000000"
android:textSize="44sp"
android:layout_alignParentRight="true"
android:paddingRight="8px"
android:paddingTop="2px"
/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/qd_pc_sp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/mDataTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textColor="#000000"
android:textSize="44sp"
android:layout_alignParentRight="true"
android:paddingTop="43px"
android:paddingRight="8px"
/>
<TextView
android:id="@+id/mutOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_gravity="right"
android:textColor="#000000"
android:layout_alignParentLeft="true"
android:layout_alignBaseline="@+id/mDataTwo"
android:paddingLeft="10px"
/>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/qd1"
android:layout_height="80px"
android:layout_width="156px"
android:layout_marginTop="4px"
android:layout_marginLeft="2px"
android:layout_alignParentLeft="true"
android:layout_below="@+id/qd2"
android:background="@drawable/btn_hl_qd1_port"
android:clickable="true">
<FrameLayout
android:id="@+id/FrameCell1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/btn_wt_bl_land" >
<ImageView
android:id="@+id/qd1_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/map_signal_sought"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/map_wt_overlay_default_land"
android:clickable="true"/>
<ImageView
android:id="@+id/map_seeking_signal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<ImageView
android:id="@+id/map_gloss"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/gloss_wt_bl_land"
/>
</FrameLayout>
<FrameLayout
android:id="@+id/FrameCellMap"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
>
<ImageView
android:id="@+id/map_gloss"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/gloss_wt_bl_land"
/>
</FrameLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/qd4_hr"
android:layout_height="80px"
android:layout_width="156px"
android:layout_marginTop="4px"
android:layout_marginRight="2px"
android:layout_marginLeft="4px"
android:layout_below = "@+id/qd3"
android:layout_toRightOf="@+id/qd1"
android:background="@drawable/btn_hl_lp_land"
android:clickable="true"
>
<ImageView
android:id="@+id/qd4_image_z"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/qd4_image_divider"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/divider_wt_qd_land"
/>
<FrameLayout
android:id="@+id/FrameCell1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
>
<TextView
android:id="@+id/curzValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="46sp"
android:layout_gravity="right|bottom"
android:paddingRight="8px"
android:layout_marginBottom="32px"
/>
<TextView
android:id="@+id/curzName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="38sp"
android:textStyle="bold"
android:layout_gravity="right|bottom"
android:paddingRight="8px"
/>
</FrameLayout>
<TextView
android:id="@+id/curz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="18sp"
android:text="@string/hr_z_cardio"
android:layout_alignParentBottom="true"
android:paddingLeft="10px"
android:paddingBottom="5px"
/>
<ImageView
android:id="@+id/qd_lp_gloss"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/gloss_wt_br_land"
/>
<ImageView android:id="@+id/gUpDown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:visibility="invisible"
android:layout_marginBottom="5px"
android:background="@drawable/ic_wt_z_ad_lg"
/>
</RelativeLayout>
<RelativeLayout android:orientation="horizontal"
android:gravity="bottom" android:layout_height="wrap_content"
android:id="@+id/mControls"
android:layout_width="wrap_content">
<include layout="@layout/m" />
</RelativeLayout>
<RelativeLayout android:orientation="horizontal"
android:gravity="bottom" android:layout_height="wrap_content"
android:id="@+id/tWtCons"
android:visibility="invisible"
android:layout_width="wrap_content">
<include layout="@layout/st_wt" />
</RelativeLayout>
精彩评论