Home > DeveloperSection > Forums > How to set layout height and weight in percentage android?
Pooja Malohtra
Pooja Malohtra

Total Post:47

Points:331
Posted on    February-20-2015 6:28 AM

 Android Android Layout 
Ratings:


 1 Reply(s)
 1917  View(s)
Rate this:
How to set layout  height and weight in percentage android


Chris S
Chris S

Total Post:48

Points:336
Posted on    February-20-2015 6:38 AM

You need to add weight in your controls xml file. Here I am giving a sample, which help you to set height and weight in percentage.

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

     xmlns:tools="http://schemas.android.com/tools"

     android:layout_width="match_parent"

     android:layout_height="match_parent"

     android:orientation="vertical"

   tools:context=".MainActivity" >

   <!--weight=".5" means 50 percantage -->

   <LinearLayout

       android:layout_width="fill_parent"

       android:layout_height="0dp"

       android:layout_weight=".5"

       android:orientation="horizontal" >

       <TextView

           android:layout_width="0dp"

           android:layout_height="wrap_content"

           android:layout_weight=".5"

           android:gravity="center"

           android:text="Sample1" />

        <TextView

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight=".5"

            android:gravity="center"

            android:text="Sample2" />

    </LinearLayout>

    <LinearLayout

        android:layout_width="fill_parent"

        android:layout_height="0dp"

        android:layout_weight=".5"

        android:orientation="horizontal" >

        <Button

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight=".5"

            android:gravity="center"

            android:text="Sample1" />

        <Button

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight=".5"

            android:gravity="center"

            android:text="Sample2" />

    </LinearLayout>

</LinearLayout>

  


Don't want to miss updates? Please click the below button!

Follow MindStick