RelativeLayout and height as a percentage. Cannot use layout_below and layout_weight

I have a problem with a relative layer where its children could use layout_below and layout_weight to set its percentage height.

For example, we have a relative layout, and inside it we have three linear layouts with textual representations. Now I would like to set 25.50.25% of the height of the total height of the relative layout for three of them (linear markings). How could I do this?

I found a solution for weight_sum and andlativelayout (CLICK) , but it does not use layout_below.

How can i fix this?

I tried to add additional line layouts inside all line layouts, but then I can not use layout_below.

Here is an idea of ​​a concept image:

Enter image description here

Here is my code:

<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@+id/linlay_leftcol_notification_header" > <LinearLayout android:id="@+id/linlay_leftcol_clock_theday" android:layout_width="fill_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/tv_theday" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@string/theday" android:textColor="#FFFFFF" /> </LinearLayout> <LinearLayout android:id="@+id/linlay_leftcol_clock_thetime" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/linlay_leftcol_clock_theday" > <TextView android:id="@+id/tv_thetime" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@string/thetime" android:textColor="#FFFFFF" /> </LinearLayout> <LinearLayout android:id="@+id/linlay_leftcol_clock_thenumber_themonth_theyear" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/linlay_leftcol_clock_thetime" > <TextView android:id="@+id/tv_thenumberofday_themonth_theyear" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@string/thenumberofday_themonth_theyear" android:textColor="#FFFFFF" /> </LinearLayout> </RelativeLayout> 
+4
source share
4 answers

Try it...

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="match_parent" android:background="#ff00ff" android:orientation="vertical"> <RelativeLayout android:layout_weight="1" android:background="#ffff00" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/textView0" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="Hello 1" android:textColor="#000000" android:textSize="15dp" /> </RelativeLayout> <RelativeLayout android:layout_weight="2" android:background="#00ffff" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/textView1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="Hello 2" android:textColor="#000000" android:textSize="15dp" /> </RelativeLayout> <RelativeLayout android:layout_weight="1" android:background="#ffff00" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/textView2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="Hello 3" android:textColor="#000000" android:textSize="15dp" /> </RelativeLayout> </LinearLayout> 
+12
source

Check this:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight=".15" android:background="@android:color/background_dark" android:orientation="vertical" > <RelativeLayout android:id="@+id/rel_1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#A52A2A" > <TextView android:id="@+id/tv_theday" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="1st layout" android:textColor="#FFFFFF" /> </RelativeLayout> <RelativeLayout android:id="@+id/rel_2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#8B008B" > <TextView android:id="@+id/tv_theday" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="2ndlayout" android:textColor="#FFFFFF" /> </RelativeLayout> <RelativeLayout android:id="@+id/rel_3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#00008B" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="3rd layout" android:textColor="#FFFFFF" /> </RelativeLayout> </LinearLayout> <RelativeLayout android:id="@+id/rel_side" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight=".75" android:background="#ff0000" > <TextView android:id="@+id/tv_theday" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="side layout" android:textColor="#FFFFFF" /> </RelativeLayout> </LinearLayout> 
+3
source

You can use the weight or relative properties of the layout. You can do this 25,50,25 as follows: you align the parent left first text view, align the parent right, another text view, and align the remaining text view to the left of the first and to the right of the last. ,

0
source

Use the Table Layout and inside it you will place your text views. For the layout of the table there is an attribute "Stretch Column". There you can mention the size as "0.2.1", like this ...

0
source

Source: https://habr.com/ru/post/1440008/


All Articles