I am working on linear layout for my simple android application. I wanna make the portion of two views dynamically change based on the size ( I want to have, for a row for left to right, the first 20% is empty, and all the content is inside the rest of 80%) . For this approach, i chosen the weight for different view. I created an nested linear layout for this approach. For example, the layout hierarchy is something like this.
<linearLayout> //parent layout
<linearLayout //child 1 layout
//so that this view occupy 20% of the space regardless the width of device. I intensionally wanna keep this view empty.
<linearLayout //child 2 layout
//so that this view occupy 80% of the space regardless the width of device. and
//inside this view I have whatever view I wanna add on it.
This is a possible solution using weights:
<LinearLayout android:layout_width="match_parent" android:gravity="end" android:weightSum="1"> <!-- Your content here: --> <View android:layout_width="0dp" android:layout_weight="0.8" android:layout_gravity="end" /> </LinearLayout>