The most efficient way to create proportional views

I want to create a full screen page that looks like this:

 ---------------------------------------  
| --------  --------------------------- |  
||        ||          TextView         ||  
||        | --------------------------- |  
|| Image  | -----------------  -------- |  
|| View   ||                 ||        ||  
||        ||    TextView     ||        ||  
||        ||                 || Image  ||  
||        ||                 || View   ||  
| --------  ----------------- |        ||  
| --------------------------- |        ||  
||          TextView         ||        ||  
| ---------------------------  -------- |  
 ---------------------------------------  

where each ImageView occupies no more than 20% of the width of the parent layout.

Primary question: Indeed ... what is the best way to do this? After hours of searching, the best idea I can come up with is to get the width of the screen and just set the width of the views to at least 20% of this. However, this does not intuitively sound like a better solution. (For example, if the application does not work in full screen mode, this solution will not work.) LinearLayout will not work with the way the page is laid out (it appears that I should use RelativeLayout). And I think it would be preferable to set the width of the views based on the width of the parent's view (as opposed to the screen width), but I don’t understand how to do it, because at the time I'm trying to set the width of the views of my children, parentView. getWidth () returns 0. Does anyone have a good one,clean page creation solutions as shown above?

: - , , ? ; , . , ?

, .

+3
5

android: layout_weight XML-.

+1

.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="1" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.2"
            android:orientation="horizontal"
            android:weightSum="1" >

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.2"
                android:orientation="vertical"
                android:weightSum="1" >

                <ImageView .... />

            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

.

, , , , . , - .

+1

, . , , 4 ? , , , , , .

sdk android , , .

0

, , TextView

android:drawableTop 
android:drawableBottom 
android:drawableLeft
android:drawableRight

android:drawablePadding

API

, . , RelativeLayout.

0

. :

a) layout_weight RelativeLayouts; LinearLayout. , LinearLayouts, . ( , , ..)

b) , . - drawableLeft .. , .

c) , Android. - , , , . , 4- , , .

I'm not sure what other design details are needed for my question here; I thought that the layout drawn above would be enough. Was there anything else specific that I could say to clarify the issue?

0
source

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


All Articles