I am using the following layouts:
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:visibility="invisible"
android:id="@+id/progress"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/llSearch"
android:visibility="visible"
android:background="#50AAAAAA"
android:paddingTop="10dp"
android:gravity="center_vertical"
android:paddingBottom="10dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="72dp">
<ImageView
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:src="@drawable/abc_ic_search_api_mtrl_alpha"
android:layout_width="40dp"
android:layout_height="40dp" />
<EditText
android:textColor="@android:color/white"
android:textColorHint="@android:color/white"
android:background="@android:color/transparent"
android:visibility="visible"
android:maxLines="1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:visibility="invisible"
android:layout_marginTop="72dp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.v7.widget.RecyclerView
android:visibility="gone"
android:layout_marginTop="72dp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.myapp.custom.RevealView
android:id="@+id/reveal"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</merge>
When running the app through DDMS, I've noticed that the layout ends up being measured twice, why is this and how can I prevent overdraw?
What's also strange is that I can't figure out where the other LinearLayout
s are coming from.
Measuring twice isnt overdraw. Depending on the type of layout you're using Android might need to measure it twice because of the relationship between child views require it. This can happen with layouts like LinearLayout or RelativeLayout. For exact reason you need to check the source of those, but its hardly an issue (usually).
But if you have something like a recycleview you should avoid using big nested layouts inside.