Huge calls made to ViewRoot.draw() - android

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 reason 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>

Related

Chronometer not increment by one

I have implemented Chronometer to show call duration during Video and Audio call. Chronometer increase by one during the video call, but during the video call, it sometimes increases by one or two.
Start Chronometer after call connected
timeChronometer.setBase(SystemClock.elapsedRealtime());
timeChronometer.start();
Layout
<LinearLayout
android:id="#+id/call_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:paddingLeft="16.0dip"
android:paddingTop="23.0dip"
android:paddingRight="16.0dip">
<TextView
android:id="#+id/voip_call_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableStart="#drawable/calllogo"
android:drawableLeft="#drawable/calllogo"
android:drawablePadding="6dp"
android:text="#string/video_call_label"
android:textColor="#99ffffff"
android:textSize="14.0sp" />
</LinearLayout>
<FrameLayout
android:id="#+id/caller_contact_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:animateLayoutChanges="true"
android:paddingTop="28dip">
<ImageView
android:id="#+id/contact_photo"
android:layout_width="90.0dip"
android:layout_height="90.0dip"
android:layout_gravity="center"
android:src="#drawable/ic_circle_img"
android:scaleType="fitCenter" />
<android.support.v7.widget.AppCompatImageView
android:id="#+id/whatsapp_icon"
android:layout_width="20.0dip"
android:layout_height="20.0dip"
android:layout_gravity="bottom|center|right"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"
android:rotation="-10.0"
android:src="#drawable/icon"
android:visibility="gone" />
</FrameLayout>
<LinearLayout
android:id="#+id/name_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="16.0dip"
android:paddingTop="20.0dip"
android:paddingRight="16.0dip">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:paddingBottom="20.0dip"
android:singleLine="true"
android:text="Mukesh Singh"
android:textColor="#android:color/white"
android:textSize="26.0sp" />
</LinearLayout>
<TextView
android:id="#+id/call_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:lineSpacingMultiplier="1.5"
android:paddingLeft="12.0dp"
android:paddingRight="12.0dp"
android:paddingBottom="20.0dp"
android:text="INCOMING"
android:textColor="#99ffffff"
android:textSize="14.0sp" />
</LinearLayout>
<RelativeLayout
android:id="#+id/top_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:visibility="visible">
<ImageButton
android:id="#+id/top_minimize_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="center"
android:background="#drawable/voip_btn_background"
android:contentDescription="#string/voip_call_goto_chat_description"
android:padding="18.0dip"
android:src="#drawable/call_minimize"
android:visibility="gone" />
<Chronometer
android:id="#+id/timeChronometer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:gravity="center"
android:paddingStart="18.0dp"
android:paddingTop="24.0dp"
android:paddingEnd="18.0dp"
android:textColor="#99ffffff"
android:textSize="14.0sp"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout >

List View inside relative layout and scroll view not covering screen

I have below layout
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/searchScreenBG">
<RelativeLayout
android:id="#+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="#dimen/_7sdp">
<ImageButton
android:id="#+id/ib_hamburger"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="#dimen/_16sdp"
android:layout_marginRight="#dimen/_16sdp"
android:layout_marginTop="#dimen/_15sdp"
android:background="#android:color/transparent"
android:contentDescription="#null"
app:srcCompat="#drawable/ham_burger" />
<com.rod.com.rod.ui.views.CTextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/ib_hamburger"
android:layout_centerHorizontal="true"
android:text="#string/basic_details"
android:textColor="#color/colorGreen" />
<ImageButton
android:id="#+id/ib_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignTop="#+id/ib_hamburger"
android:layout_marginLeft="#dimen/_16sdp"
android:layout_marginStart="#dimen/_16sdp"
android:background="#android:color/transparent"
android:contentDescription="#null"
app:srcCompat="#drawable/left_arrow" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/reg_no_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_5sdp"
android:layout_below="#+id/title_bar"
android:background="#color/colorWhite">
<TextView
android:id="#+id/tv_reg_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp"
android:textColor="#color/colorLightGrey" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/reg_no_layout"
>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:layout_marginRight="#dimen/_10sdp"
android:layout_marginLeft="#dimen/_10sdp"
android:layout_weight="1">
<RelativeLayout
android:id="#+id/basic_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/_10sdp"
android:background="#drawable/list_item_bg"
android:paddingBottom="#dimen/_10sdp">
<TextView
android:id="#+id/tv_district_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="50dp"
android:layout_marginStart="50dp"
android:layout_marginTop="11dp"
android:text="#string/district"
android:textColor="#color/colorBlack"
android:textSize="#dimen/_13sdp" />
<TextView
android:id="#+id/tv_district"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_district_label"
android:layout_alignStart="#+id/tv_district_label"
android:layout_below="#+id/tv_district_label"
android:text="TextView"
android:textColor="#color/colorLightGrey" />
<TextView
android:id="#+id/tv_tehsil_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/tv_district"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="75dp"
android:layout_marginRight="75dp"
android:text="#string/tehsil"
android:textColor="#color/colorBlack" />
<TextView
android:id="#+id/tv_tehsil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/tv_district"
android:layout_alignLeft="#+id/tv_tehsil_label"
android:layout_alignStart="#+id/tv_tehsil_label"
android:text="TextView"
android:textColor="#color/colorLightGrey" />
<TextView
android:id="#+id/tv_date_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_district"
android:layout_alignStart="#+id/tv_district"
android:layout_below="#+id/tv_district"
android:layout_marginTop="13dp"
android:text="#string/date"
android:textColor="#color/colorBlack" />
<TextView
android:id="#+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_date_label"
android:layout_alignStart="#+id/tv_date_label"
android:layout_below="#+id/tv_date_label"
android:text="TextView"
android:textColor="#color/colorLightGrey" />
<TextView
android:id="#+id/tv_jild_no_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/tv_date_label"
android:layout_alignLeft="#+id/tv_tehsil"
android:layout_alignStart="#+id/tv_tehsil"
android:text="#string/jild_no"
android:textColor="#color/colorBlack" />
<TextView
android:id="#+id/tv_jild_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_jild_no_label"
android:layout_alignStart="#+id/tv_jild_no_label"
android:layout_below="#+id/tv_jild_no_label"
android:text="TextView"
android:textColor="#color/colorLightGrey" />
<TextView
android:id="#+id/tv_party_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_date"
android:layout_alignStart="#+id/tv_date"
android:layout_below="#+id/tv_date"
android:layout_marginTop="13dp"
android:text="#string/party"
android:textColor="#color/colorBlack" />
<TextView
android:id="#+id/tv_party"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_party_label"
android:layout_alignStart="#+id/tv_party_label"
android:layout_below="#+id/tv_party_label"
android:text="TextView"
android:textColor="#color/colorLightGrey" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:layout_below="#+id/basic_details"
android:layout_marginTop="13dp"
android:background="#drawable/list_item_bg">
<TextView
android:id="#+id/tv_member_details_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="#dimen/_40sdp"
android:layout_marginStart="#dimen/_40sdp"
android:layout_marginTop="14dp"
android:text="#string/member_details"
android:textColor="#color/colorBlack"
android:textSize="#dimen/_16sdp" />
<ListView
android:id="#+id/lv_members"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/tv_member_details_label"
android:layout_marginLeft="#dimen/_40sdp"
android:layout_marginRight="#dimen/_40sdp"
android:layout_marginStart="#dimen/_40sdp"
android:layout_marginTop="16dp"
android:divider="#color/colorLightGrey"
android:dividerHeight="#dimen/_1sdp" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</FrameLayout>
I want to make the relative layout below basic_layout cover the whole of the rest screen. How can I achieve that. After searching I had found that I should put a linear layout inside my scroll view, and then relative layouts should added. But that's of no help.
I want hierachy something like below:
----RelativeLayout
-------TitleBar
-------TextView
-------ScrollView (rest of screen)
----------RelativeLayout (upper portion of scroll view)
------------TextViews
----------RelativeLayout (rest of scrol view)
-------------TextView
-------------ListView
Any help please?
Actually the problem is that you are using 2 layouts in your scrollview so the listview won't take the scroll of itself and it will limit the list height as well. To go around this you need to pass fix value to your listview then it will show completely within that specified height. And the rest of the layout if you want to get exactly as you have shown in the picture you need to use cardview instead.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:layout_below="#+id/basic_details"
android:layout_marginTop="13dp"
android:layout_marginBottom="10dp"
android:background="#drawable/list_item_bg">
<TextView
android:id="#+id/tv_member_details_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="#dimen/_40sdp"
android:layout_marginStart="#dimen/_40sdp"
android:layout_marginTop="14dp"
android:text="#string/member_details"
android:textColor="#color/colorBlack"
android:textSize="16dp" />
<ListView
android:id="#+id/lv_members"
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/tv_member_details_label"
android:layout_marginLeft="#dimen/_40sdp"
android:layout_marginRight="#dimen/_40sdp"
android:layout_marginStart="#dimen/_40sdp"
android:layout_marginTop="16dp"
android:divider="#color/colorLightGrey"
android:dividerHeight="#dimen/_1sdp" />
</RelativeLayout>

How to reduce layout loading time of a complex layout with custom views in android?

I have an activity and a fragment. Where fragment will be loaded dynamically in activity. Fragment has around 20 views and most of them are custom views. For loading the fragment its taking around 3 seconds, this time is just for loading the layout, without any initialization or functionality. I feel 3 seconds is more and want to reduce it to 1 second. What could be the possible ways to achieve this.
Things I did:
** Removed weights and nested layouts.
** Removed unused attributes of view
** Flattened the layout hierarchy.
Layout :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gauge="http://schemas.android.com/apk/res/com.test.app.testApp"
xmlns:customview="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background_light_grey" >
<RelativeLayout
android:id="#+id/top_components_dummy"
android:layout_width="match_parent"
android:layout_height="135dp"
android:orientation="horizontal" >
<RelativeLayout
android:id="#+id/ dummy_layout"
android:layout_width="370dp"
android:layout_toLeftOf="#+id/host_layout"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/dummy_parent"
android:layout_width="280dp"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/water_and_drain_tactile"
android:orientation="horizontal" >
<FrameLayout
android:id="#+id/dummy_parent_water"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="40dp"
android:layout_marginRight="20dp" >
<com.test.app.ui.components.CustomView
android:id="#+id/level_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:src="#drawable/xyz" />
<ImageView
android:layout_width="85dp"
android:layout_height="4dp"
android:layout_gravity="center|bottom"
android:layout_marginBottom="20dp"
android:background="#drawable/empty_indiactor"
android:contentDescription="#string/empty_string"
android:visibility="gone" />
</FrameLayout>
<FrameLayout
android:id="#+id/dummy_parent_drain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="40dp" >
<com.test.app.ui.components.CustomView
android:id="#+id/drain_level_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="45dp"
android:src="#drawable/xyz" />
<ImageView
android:layout_width="85dp"
android:layout_height="4dp"
android:layout_gravity="top|center"
android:layout_marginTop="20dp"
android:background="#drawable/empty_indiactor"
android:contentDescription="#string/empty_string"
android:visibility="gone" />
</FrameLayout>
</LinearLayout>
<TextView
android:id="#+id/Waterdummy_TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="30dp"
android:layout_marginTop="10dp"
android:layout_toLeftOf="#+id/dummyCenter"
android:text="Water"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<View
android:id="#+id/dummyCenter"
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:background="#00ffffff" />
<TextView
android:id="#+id/Draindummy_TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/dummyCenter"
android:text="Drain"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/host_layout"
android:layout_width="400dp"
android:layout_centerHorizontal="true"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/host_Stop_Background"
android:layout_width="120dp"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/xyz"
android:contentDescription="#string/empty_string" />
<ImageView
android:id="#+id/dull_stop_icon"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_above="#+id/host_stop_text"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp"
android:contentDescription="#string/empty_string"
android:scaleType="fitXY"
android:src="#drawable/xyz" />
<TextView
android:id="#+id/host_stop_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:text="STOP"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" />
<RelativeLayout
android:id="#+id/host_Rate_Layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toLeftOf="#+id/host_Stop_Background" >
<ImageView
android:id="#+id/host_Rate_Icon"
android:layout_width="120dp"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/xyz"
android:contentDescription="#string/empty_string" />
<TextView
android:id="#+id/host_rate_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/host_rate_unit_textView"
android:layout_centerHorizontal="true"
android:layout_marginBottom="-5dp"
android:gravity="bottom|center_horizontal"
android:text="1.5"
android:textAlignment="gravity"
android:textColor="#000000"
android:textSize="34sp" />
</RelativeLayout>
<ImageView
android:id="#+id/host_system_Icon"
android:layout_width="120dp"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_toRightOf="#+id/host_Stop_Background"
android:background="#drawable/host_system_top_tactile"
android:contentDescription="#string/empty_string"
android:paddingBottom="18dp"
android:paddingTop="18dp"
android:scaleType="fitCenter"
android:src="#drawable/xyz" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/dull_rate_layout"
android:layout_width="350dp"
android:layout_toRightOf="#+id/host_layout"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/dull_rate_layout"
android:layout_width="175dp"
android:layout_height="match_parent" >
<TextView
android:id="#+id/dull_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="#string/dull_rate"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="130dp"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/xyz" />
<TextView
android:id="#+id/dull_rate_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/dull_rate_unit_textView"
android:layout_centerHorizontal="true"
android:layout_marginBottom="-5dp"
android:gravity="bottom|center_horizontal"
android:text="500"
android:textAlignment="gravity"
android:textColor="#000000"
android:textSize="36sp" />
<TextView
android:id="#+id/dull_rate_unit_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:text="mL/min"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/salad_layout"
android:layout_width="175dp"
android:layout_height="match_parent"
android:layout_toRightOf="#+id/dull_rate_layout" >
<TextView
android:id="#+id/salad_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="#string/salad"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<ImageView
android:id="#+id/salad_Icon"
android:layout_width="130dp"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/dull_salad_tactile"
android:contentDescription="#string/empty_string"
android:paddingBottom="18dp"
android:paddingTop="18dp"
android:scaleType="fitCenter"
android:src="#drawable/xyz" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/midLinear"
android:layout_width="match_parent"
android:layout_height="460dp"
android:layout_below="#+id/top_components_dummy" >
<TextView
android:id="#+id/boomSpeed_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="#string/boom_speed"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<TextView
android:id="#+id/boomSpeed_Value_Text"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_below="#+id/boomSpeed_textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="-5dp"
android:gravity="center"
android:maxLength="3"
android:text="300"
android:textColor="#android:color/black"
android:textSize="50sp"
android:textStyle="normal" />
<ImageView
android:id="#+id/imageView_down"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_alignBottom="#+id/boomSpeed_Value_Text"
android:layout_marginRight="5dp"
android:layout_toLeftOf="#+id/boomSpeed_Value_Text"
android:scaleType="fitXY"
android:src="#drawable/xyz" />
<ImageView
android:id="#+id/imageView_up"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_alignBottom="#+id/boomSpeed_Value_Text"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/boomSpeed_Value_Text"
android:src="#drawable/xyz" />
<TextView
android:id="#+id/boom_Speed_Value_Unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/boomSpeed_Value_Text"
android:layout_centerHorizontal="true"
android:layout_marginTop="-10dp"
android:text="mL/min"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#444444" />
<ImageView
android:id="#+id/IV_boomSpeed"
android:layout_width="240dp"
android:layout_height="240dp"
android:layout_below="#+id/boom_Speed_Value_Unit"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:hapticFeedbackEnabled="true"
android:src="#drawable/xyz" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
android:layout_toLeftOf="#+id/IV_boomSpeed"
android:gravity="center_vertical" >
<ImageView
android:layout_width="380dip"
android:layout_height="380dip"
android:layout_centerInParent="true"
android:src="#drawable/xyz" />
<com.test.app.ui.components.CustomView1
android:id="#+id/circularprogressbar2"
android:layout_width="345dip"
android:layout_height="345dip"
android:layout_centerInParent="true"
customview:cpb_backgroundColor="#EDEDED"
customview:cpb_borderColor="#22B7B3"
customview:cpb_maintitle="#string/time_remaining"
customview:cpb_progressColor="#22B7B3" />
<RelativeLayout
android:id="#+id/clickablearea"
android:layout_width="180dip"
android:layout_height="80dip"
android:layout_alignTop="#+id/circularprogressbar2"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dip"
android:background="#00fff000" >
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
android:layout_toRightOf="#+id/IV_boomSpeed"
android:gravity="center_vertical" >
<ImageView
android:layout_width="380dip"
android:layout_height="380dip"
android:layout_centerInParent="true"
android:src="#drawable/dialsbg" />
<ImageView
android:id="#+id/IV_StopML"
android:layout_width="120dip"
android:layout_height="80dip"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginBottom="54dp"
android:src="#drawable/xyz" />
<TextView
android:layout_width="100dip"
android:layout_height="80dip"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginBottom="40dp"
android:layout_marginRight="15dp"
android:gravity="center"
android:text="STOP\n ML"
android:textColor="#android:color/holo_red_dark"
android:textStyle="bold" />
<com.test.app.ui.components.CustomView1
android:id="#+id/circularprogressbar3"
android:layout_width="345dip"
android:layout_height="345dip"
android:layout_centerInParent="true"
customview:cpb_borderColor="#E7AB0F"
customview:cpb_progressColor="#e2a000"
customview:backgroundColor="#EDEDED"
customview:goal="#string/goal"
customview:goal_unit="mL"
customview:goal_value="2800"
customview:ml_unit="mL"
customview:rate="#string/rate"
customview:rate_unit="mL/hr"
customview:rate_value="700"
customview:removed_title="#string/removed"
customview:removed_value="1500" />
<RelativeLayout
android:id="#+id/editMLGoal_clickArea"
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_alignStart="#+id/circularprogressbar3"
android:layout_marginLeft="60dip"
android:layout_marginTop="210dip"
android:background="#00fff000" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/editMLRate_clickArea"
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_alignEnd="#+id/circularprogressbar3"
android:layout_marginRight="60dip"
android:layout_marginTop="210dip"
android:background="#00fff000" >
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/RL_DialView2"
android:layout_width="300dp"
android:layout_height="190dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginBottom="-40dp" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="170dp"
android:layout_height="80dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:scaleType="fitXY"
android:src="#drawable/xyz" />
<com.test.app.ui.components.CustomView2
android:id="#+id/gauge_view2"
android:layout_width="match_parent"
android:layout_height="match_parent"
gauge:isFloat="false"
gauge:scaleEndValue="400"
gauge:scaleMaxLimit="350"
gauge:scaleMinLimit="150"
gauge:scaleStartValue="70"
gauge:showLimitText="true"
gauge:showNeedle="true"
gauge:showRanges="true"
gauge:showScale="false"
gauge:showText="true"
gauge:textTitle="#string/ven"
gauge:textUnit="mmHg"
gauge:textUnitColor="#000000"
gauge:textValueColor="#000000" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/RL_DialView1"
android:layout_width="220dp"
android:layout_height="140dp"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:layout_marginBottom="-20dp"
android:layout_toLeftOf="#+id/RL_DialView2" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="120dp"
android:layout_height="70dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:scaleType="fitXY"
android:src="#drawable/xyz" />
<com.test.app.ui.components.CustomView2
android:id="#+id/gauge_view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
gauge:isFloat="false"
gauge:scaleEndValue="500"
gauge:scaleMaxLimit="400"
gauge:scaleMinLimit="-200"
gauge:scaleStartValue="-300"
gauge:showLimitText="true"
gauge:showNeedle="true"
gauge:showRanges="true"
gauge:showScale="false"
gauge:showText="true"
gauge:textTitle="#string/art"
gauge:textUnit="mmHg"
gauge:textUnitColor="#000000"
gauge:textValueColor="#000000" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/RL_DialView4"
android:layout_width="220dp"
android:layout_height="140dp"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:layout_marginBottom="-20dp"
android:layout_toRightOf="#+id/RL_DialView2" >
<ImageView
android:id="#+id/imageView4"
android:layout_width="120dp"
android:layout_height="70dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:scaleType="fitXY"
android:src="#drawable/xyz" />
<com.test.app.ui.components.CustomView2
android:id="#+id/gauge_view4"
android:layout_width="match_parent"
android:layout_height="match_parent"
gauge:isFloat="true"
gauge:scaleEndValue="40"
gauge:scaleMaxLimit="38"
gauge:scaleMinLimit="36"
gauge:scaleStartValue="34"
gauge:showLimitText="true"
gauge:showNeedle="true"
gauge:showRanges="true"
gauge:showScale="false"
gauge:showText="true"
gauge:textTitle="#string/dt"
gauge:textUnit="\u2103"
gauge:textUnitColor="#000000"
gauge:textValueColor="#000000" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/RL_DialView3"
android:layout_width="220dp"
android:layout_height="140dp"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:layout_marginBottom="-20dp"
android:layout_toLeftOf="#+id/RL_DialView1" >
<ImageView
android:id="#+id/imageView3"
android:layout_width="120dp"
android:layout_height="70dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:scaleType="fitXY"
android:src="#drawable/xyz" />
<com.test.app.ui.components.CustomView2
android:id="#+id/gauge_view3"
android:layout_width="match_parent"
android:layout_height="match_parent"
gauge:isFloat="false"
gauge:scaleEndValue="320"
gauge:scaleMaxLimit="300"
gauge:scaleMinLimit="90"
gauge:scaleStartValue="70"
gauge:showLimitText="true"
gauge:showNeedle="true"
gauge:showRanges="true"
gauge:showScale="false"
gauge:showText="true"
gauge:textTitle="#string/tmp"
gauge:textUnit="mmHg"
gauge:textUnitColor="#000000"
gauge:textValueColor="#000000" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/RL_DialView5"
android:layout_width="220dp"
android:layout_height="140dp"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:layout_marginBottom="-20dp"
android:layout_toRightOf="#+id/RL_DialView4" >
<ImageView
android:id="#+id/imageView5"
android:layout_width="120dp"
android:layout_height="70dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:scaleType="fitXY"
android:src="#drawable/xyz" />
<com.test.app.ui.components.CustomView2
android:id="#+id/gauge_view5"
android:layout_width="match_parent"
android:layout_height="match_parent"
gauge:isFloat="true"
gauge:scaleEndValue="17"
gauge:scaleMaxLimit="15.9"
gauge:scaleMinLimit="13.1"
gauge:scaleStartValue="12"
gauge:showInnerRim="false"
gauge:showNeedle="true"
gauge:showRanges="true"
gauge:showScale="false"
gauge:showText="true"
gauge:textTitle="#string/cond"
gauge:textUnit="mS/cm"
gauge:textUnitColor="#000000"
gauge:textValueColor="#000000" />
</RelativeLayout>
You can check the Layout Optimizating guide:
Avoid nested ViewGroup. You should make your Layout as low-level hierarchy as possible
Using nested instances of LinearLayout can lead to an excessively deep view hierarchy. Furthermore, nesting several instances of LinearLayout that use the layout_weight parameter can be especially expensive as each child needs to be measured twice. This is particularly important when the layout is inflated repeatedly, such as when used in a ListView or GridView.
It is always good practice to run the lint tool on your layout files to search for possible view hierarchy optimizations.
Using ViewStub:
Sometimes your layout might require complex views that are rarely used. Whether they are item details, progress indicators, or undo messages, you can reduce memory usage and speed up rendering by loading the views only when they are needed
Using RelativeLayouts are expensive, as laying out the views is a 'complex' task - each time you inflate the xml, the inflater must calculate the relations between the views, which is rather expensive.
You should try to use as much LinearLayouts as you can. This will boost things up a bit. LinearLayouts are much more faster to inflates, as the relations are at most 2 nodes per view.
Have you heard from CustomViews?
You can lay out the child views directly. So it don't need calculate again and again and again.
For example:
<RelativeLayout
android:id="#+id/RL_DialView2"
android:layout_width="300dp"
android:layout_height="190dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginBottom="-40dp" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="170dp"
android:layout_height="80dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:scaleType="fitXY"
android:src="#drawable/xyz" />
<com.test.app.ui.components.CustomView2
android:id="#+id/gauge_view2"
android:layout_width="match_parent"
android:layout_height="match_parent"
gauge:isFloat="false"
gauge:scaleEndValue="400"
gauge:scaleMaxLimit="350"
gauge:scaleMinLimit="150"
gauge:scaleStartValue="70"
gauge:showLimitText="true"
gauge:showNeedle="true"
gauge:showRanges="true"
gauge:showScale="false"
gauge:showText="true"
gauge:textTitle="#string/ven"
gauge:textUnit="mmHg"
gauge:textUnitColor="#000000"
gauge:textValueColor="#000000" />
</RelativeLayout>
This is 5 times in your Layout.
Change the RelativeLayout to a ImageWithCustomView2Layout which extends from ViewGroup.
Then override onMeasure(int widthMeasureSpec, int heightMeasureSpec) and onLayout(boolean changed, int left, int top, int right, int bottom).
However. When you use CustomViews which know exactly the position (and size) of its Childs it will be much faster.
Learn more about CustomViews at:
DAC or
GitHub Examples (1), (2)
Our can also a look at this post at medium.

ScrollView not works on Relative Layout

I am trying to make my layout Scrollable by adding ScrollView as an parent for my Relative Layout.But my layout not scrolled.I have added the fillport property to true.
Here is my xml file:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/repActivityTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:ellipsize="middle"
android:textSize="18sp"
android:background="#android:color/darker_gray"
android:text="#string/representativeTitle" />
<TextView
android:id="#+id/repStreet"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/repImage"
android:layout_marginTop="14sp"
android:layout_toRightOf="#+id/repImage"
android:layout_margin="3sp"
android:text="#string/repStreet" />
<TextView
android:id="#+id/repState"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/repStreet"
android:layout_toRightOf="#+id/repImage"
android:text="#string/repState" />
<TextView
android:id="#+id/repCountry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/repState"
android:layout_below="#+id/repState"
android:text="#string/repCountry" />
<com.google.android.maps.MapView
android:id="#+id/repMap"
android:layout_width="100dip"
android:layout_height="100dip"
android:paddingTop="2dp"
android:layout_marginTop="2dp"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/repImage"
android:apiKey="0lsQmtr2D241pSL53j0vQ2lYUs4_ZIWkIHyHAKw" >
</com.google.android.maps.MapView>
<View
android:id="#+id/firstHorizontalLine"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/repMap"
android:layout_marginTop="54dp"
android:background="#android:color/black" />
<TextView
android:id="#+id/issues2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/issues1"
android:layout_centerVertical="true"
android:text="#string/issues2" />
<View
android:id="#+id/secondHorizontalLine"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/accomplishments"
android:background="#android:color/black" />
<TextView
android:id="#+id/issues"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignBottom="#+id/firstHorizontalLine"
android:layout_alignRight="#+id/repStreet"
android:text="#string/issues" />
<TextView
android:id="#+id/accomplish2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/accomplish1"
android:layout_below="#+id/accomplish1"
android:layout_marginTop="18dp"
android:text="#string/accomplishments2" />
<TextView
android:id="#+id/promises"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/issues"
android:gravity="center"
android:layout_below="#+id/accomplish2"
android:text="#string/promises" />
<View
android:id="#+id/thirdHorizontalLine"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/black"
android:layout_alignParentLeft="true"
android:layout_below="#+id/promises" />
<TextView
android:id="#+id/accomplishments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/issues2"
android:gravity="center"
android:layout_toLeftOf="#+id/repMap"
android:text="#string/accomplishments" />
<TextView
android:id="#+id/accomplish1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/secondHorizontalLine"
android:layout_marginTop="21dp"
android:text="#string/accomplishments1" />
<TextView
android:id="#+id/issues1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/issues2"
android:layout_alignParentLeft="true"
android:layout_marginBottom="14dp"
android:text="#string/issues1" />
<ImageView
android:id="#+id/repImage"
android:layout_width="100dip"
android:layout_height="100dip"
android:layout_alignParentLeft="true"
android:layout_below="#+id/repActivityTitle"
android:contentDescription="#string/representativeImage"
android:paddingTop="2dp"
android:layout_marginTop="2dp"
android:scaleType="centerCrop"
android:src="#drawable/icon" />
<TextView
android:id="#+id/promise1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/thirdHorizontalLine"
android:layout_marginTop="19dp"
android:text="#string/promises1" />
<TextView
android:id="#+id/promise2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/promise1"
android:text="#string/promises2" />
</RelativeLayout>
</ScrollView>
Here I have used the ScrollView but the full content of layout is not as showing.As scrolls not work here.
Try to remove this line and check
android:fillViewport="true"
And also you can try height of relativelayout to match_parent instead of wrap_content
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>

I can't get the button to the bottom of the layout

I'm trying to get the button to the bottom the layout, and it just won't work...
The button is displaying it self on the image that should be above it.
Here is the xml code:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:layout_gravity="center"
>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="28dp"
android:layout_marginTop="32dp" />
<TextView
android:id="#+id/txtAppName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageView1"
android:layout_marginLeft="22dp"
android:layout_toRightOf="#+id/imageView1"
android:text=""
android:textSize="36px"
android:textStyle="bold" />
<TextView
android:id="#+id/txtAppAuthor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txtAppName"
android:layout_below="#+id/txtAppName"
android:layout_marginTop="5px"
android:text=""
android:textSize="24px"
android:textStyle="normal" />
<TextView
android:id="#+id/txtAppDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView1"
android:layout_below="#+id/imageView1"
android:layout_marginTop="20dp"
android:maxHeight="350px"
android:text=""
android:width="600px"
android:maxLines="10"
android:scrollbars = "vertical"
/>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txtAppDesc"
android:layout_below="#+id/txtAppDesc"
android:layout_marginTop="30dp" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageView2"
android:layout_toRightOf="#+id/imageView2" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageView3"
android:layout_toRightOf="#+id/imageView3"
android:visibility="visible" />
<Button
android:id="#+id/btnInstall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_alignBottom="#+id/imageview4"
android:text="Download & Install" />
</RelativeLayout>
</ScrollView>
And the result is:
Thanx upfront.
You used android:layout_alignBottom="#+id/imageview4"
This means you align the bottom of your button with the bottom of your image.
You have to use android:layout_below="#+id/imageview4"
EDIT: I don't say this is the best solution, because of multiple layouts (for optimisation...) but this should work:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:layout_gravity="center"
>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="28dp"
android:layout_marginTop="32dp"/>
<TextView
android:id="#+id/txtAppName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageView1"
android:layout_marginLeft="22dp"
android:layout_toRightOf="#+id/imageView1"
android:text=""
android:textSize="36px"
android:textStyle="bold"/>
<TextView
android:id="#+id/txtAppAuthor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txtAppName"
android:layout_below="#+id/txtAppName"
android:layout_marginTop="5px"
android:text=""
android:textSize="24px"
android:textStyle="normal"/>
<TextView
android:id="#+id/txtAppDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView1"
android:layout_below="#+id/imageView1"
android:layout_marginTop="20dp"
android:maxHeight="350px"
android:text=""
android:width="600px"
android:maxLines="10"
android:scrollbars="vertical"
/>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txtAppDesc"
android:layout_below="#+id/txtAppDesc"
android:layout_marginTop="30dp"/>
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageView2"
android:layout_toRightOf="#+id/imageView2"/>
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageView3"
android:layout_toRightOf="#+id/imageView3"
android:visibility="visible"/>
</RelativeLayout>
<Button
android:id="#+id/btnInstall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Download & Install"/>
</LinearLayout>
</ScrollView>
I added a linear layout in which I put the content, and the button.
Hope this will work.
Do you just want the image that the button is over to shrink in order to make room for it? If so, you need to put the Imageview that contains that image as the very last item in your relative layout. It's going to allocate space for everything but the image, and then give the remaining space to the image, which is why it needs to be last.
Also, I suggest giving your imageViews more informative names than "imageView#", since it's kind of difficult to tell which is which.
You might want to wrap you images in a HorizontalScrollView to maintain full height and width of all your images. I changed a lot of the ViewGroups' widths and heights to accommodate the HorizontalScrollView, finally I set the Button below the images:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fillViewport="true" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="28dp"
android:layout_marginTop="32dp" />
<TextView
android:id="#+id/txtAppName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageView1"
android:layout_marginLeft="22dp"
android:layout_toRightOf="#+id/imageView1"
android:text=""
android:textSize="36px"
android:textStyle="bold" />
<TextView
android:id="#+id/txtAppAuthor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txtAppName"
android:layout_below="#+id/txtAppName"
android:layout_marginTop="5px"
android:text=""
android:textSize="24px"
android:textStyle="normal" />
<TextView
android:id="#+id/txtAppDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView1"
android:layout_below="#+id/imageView1"
android:layout_marginTop="20dp"
android:maxHeight="350px"
android:maxLines="10"
android:scrollbars="vertical"
android:text=""
android:width="600px" />
<HorizontalScrollView
android:id="#+id/images"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtAppDesc"
android:layout_marginTop="30dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</HorizontalScrollView>
<Button
android:id="#+id/btnInstall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/images"
android:layout_centerHorizontal="true"
android:text="Download & Install" />
</RelativeLayout>
</ScrollView>
Understand that nesting a HorizontalScrollView inside a ScrollView (or vica versa) does not create a smooth scrolling effect in the x & y directions simultaneously. But you can create this effect as discussed here: Scrollview vertical and horizontal in android.

Categories

Resources