Split widget on screen

0

I want to split two widget within LayoutLinear , both TextView .

If I use "orientation=" horizontal " and TextView use the android:layout_weight="1" attribute, the widgets are split on screen at a 50% one!

So my question is:

  

Is there any way to split these two widgets on screen in different proportions? such as 20% of the screen for one and 80% for the other?

     
    

This without using ready-made measures     for example, the screen has 300px, so I determined that one will have 100px and the other 200px

  
    
asked by anonymous 30.06.2016 / 04:44

1 answer

3

You can do this:

<LinearLayout android:id="@+id/horizontalLinharLayout"
              android:orientation="horizontal"
              android:weightSum="10"
              android:layout_width="math_parent"
              android:layout_height="math_parent">

    <TextView android:id="@+id/tx80Percent"
              android:layout_weight="8"
              android:layout_height="wrap_content"
              android:layout_width="0dp" />

    <TextView android:id="@+id/tx20Percent"
              android:layout_weight="2"
              android:layout_height="wrap_content"
              android:layout_width="0dp" />
</LinearLayout>

Remembering that the sum of layout_weight within LinearLayout is equal to 100% (in this case 10), then it is only divide accordingly. layout_width="0dp" is to ensure TextView will not try to do other calculations in parallel. This is even shown as a warning in Android Studio.

I hope I have helped \ o /

    
30.06.2016 / 05:07