Example:
I want to set child LinearLayout height = 50% of parrent LinearLayout in Android. Like in HTML.

To set height in percents I do some trick with android:layout_weight and android:weightSum

Here the screenshot:

Android Layout height equals 50 percents of parrent

Android Layout height equals 50 percents of parrent

To do this you need do somethind like this. Look at code below:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" 
	android:layout_width="match_parent"
	android:layout_height="match_parent" 
	android:weightSum="100">
	<LinearLayout android:layout_weight="50"
		android:layout_width="match_parent" 
		android:id="@+id/linearLayout1"
		android:layout_height="wrap_content" 
		android:orientation="vertical"></LinearLayout>
</LinearLayout>


1 Comment

Mohamed Amine Zghal · 21 January, 2017 at 12:40

How to set margin with % of linearlayout height?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.