Split screen percentage

I am trying to create a Relative layout when it displays 3 views vertically. The first view is the text and it is assumed that it will occupy 10% of the screen. The second view is an image and should take up 50% of the screen. 3rd view is text and should take the remaining 40%.

The way I do this is by manually adjusting the size of the image and evaluating that it is close to what I want by looking at it. I am sure this is the wrong way. So how can I do this? Basically, how can I determine the percentage of the screen as a percentage, and can I do this using the relative layout?

thanks

+6
source share
2 answers

You should use LinearLayout with android:weightSum .

use android:weightSum="100" in the root layout and give android:layout_weight as per your requirement. And android:layout_height="0dp" for each View .

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:weightSum="100" > <TextView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="10" /> <ImageView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="50" android:contentDescription="@string/image" android:src="@drawable/ic_launcher" /> <TextView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="40" /> </LinearLayout> 

Hope this helps you.

+8
source

You can do this using the LinearLayout and android:layout_weight :

 <?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"> <View android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /> <View android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="5" /> <View android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="4" /> </LinearLayout> 
+3
source

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


All Articles