I have a working layout looking something like this:
This is the according xml:
<FrameLayout
android:id="@+id/red"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/green"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="@drawable/blueyellow_border">
<ImageButton
android:id="@+id/blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="@drawable/selector_blue_border"
android:padding="5dp"
android:src="@drawable/blue_icon"
tools:ignore="ContentDescription"/>
<ImageButton
android:id="@+id/yellow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_toRightOf="@id/blue"
android:background="@drawable/selector_yellow_border"
android:padding="5dp"
android:src="@drawable/selector_yellow_icon"
tools:ignore="ContentDescription"/>
</RelativeLayout>
<TextView
android:id="@+id/green"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="@drawable/green_border"
android:text="@string/green_string"/>
</RelativeLayout>
</FrameLayout>
The problem is that this layout is not efficient according to Hierarchy View. In the following I am referring to the traffic light color scheme of Hierarchy View.
- For the "yellow"
ImageButton
I get "red" for layout and "yellow" for measuring. - For the "blue"
ImageButton
I get "yellow" for drawing. - For the "green"
TextView
I get "yellow" for layout. - For the inner
RelativeLayout
I get "red" for measuring and drawing. - And for the outer
RelativeLayout
I get "red" for measuring and "yellow" for layout and drawing.
Is there a way to do what I am doing (i.e. use selectors for backgrounds and image sources) and still be more efficient?