Reputation: 179
The attached image contain 3 layouts
Both the linear layouts are of same size and are overlapped.
All i want to know is how to arrange those two linear layouts inside the relative layout so that Linear layout 1 & Linear layout 2 will have 90% of parent height. Also linear layout 1 must be aligned to the top of relative layout while linear layout 2 to the bottom of relative layout.
Any simple working solution will be appreciated.( I'm a newbie to android studio)
Upvotes: 1
Views: 2094
Reputation: 58
From the Android documentation:
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
app:layout_heightPercent="90%"
android:layout_alignParentTop="true"/>
<LinearLayout
android:layout_width="match_parent"
app:layout_heightPercent="90%"
android:layout_alignParentBottom="true"/>
</android.support.percent.PercentRelativeLayout>
The order in which the LinearLayouts will overlap corresponds to the order in which they are defined.
Upvotes: 1
Reputation: 6181
Nice question, What you can do is use PercentRelativeLayout instead of RelativeLayout
so you can adjust that 90% height, and then use this property
android:layout_alignParentTop = true
for your first LinearLayout
and
android:layout_alignParentBottom = true
for second RelativeLayout
It will stick your LinearLayouts
inside RelativeLayout
as you want.
See this questions for how to use PercentRelativeLayout here
And If you also want Layering effect as you saw in one of pic use
android:elevation property on your both `LinearLayout`.
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
app:layout_heightPercent="90%"
android:layout_alignParentTop="true"/>
<LinearLayout
android:layout_width="match_parent"
app:layout_heightPercent="90%"
android:layout_alignParentBottom="true"/>
</android.support.percent.PercentRelativeLayout>
Upvotes: 0
Reputation: 1647
Here is another Way
android:gravity
property for both Linear Layouts (1'st Layout Top & 2'nd Layout Bottom.Then you can get the required result.
Upvotes: 0