Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android how to split between two textview the full width of screen exactly fifty fifty percent?

I have two TextView in a RelativeLayout. How to set the TextViews if I want those always (different screen resolution for example 540x960) the width of each TextView is the 50 percent of the full UI width? I would set size of both TextView to always 50 percent of full width of UI. Need to stretching of TextViews on different screen resolutions. How can I do this?

like image 875
Laszlo Avatar asked Nov 18 '12 15:11

Laszlo


1 Answers

Whenever split some view like (Button , Text View) in equally in Horizontal / Vertical

android:weight Sum / android:layout_weight Technique use...

Must remember one thing these technique must support in Linear Layout only but here you want to use Relative Layout so that simply put your Linear Layout inside Relative Layout ..

Must Follow These Rules :

1> set android:weight Sum into your Linear Layout

2> set android:layout_width each child View inside "0dp"

3> set android:layout_weight each child View depend upon how many child view & android:weight Sum(e.g: android:weight Sum = "2" & two child view then layout_weight="1" , layout_weight="1")

Ex:

     <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="2" >

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="child View 1" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="child View 2"/>
        </LinearLayout>
    </RelativeLayout>

if Layout Orientation is Vertical then only set android:layout_height is "0dp" instead of android:layout_width

like image 86
Dhruv Raval Avatar answered Nov 15 '22 19:11

Dhruv Raval