Распределить три линейных макета в одном родительском относительном макете - PullRequest
0 голосов
/ 17 октября 2018

У меня есть следующий код, в котором я хочу, чтобы три линейных макета распределялись по родительскому относительному макету, как дочерние виды в одном линейном макете, распределяются в линейном макете.Я попытался использовать 'layout_weight = "1" в тегах Linear Layout, но не получил ожидаемого результата.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/root_relative_layout">

    <LinearLayout
        android:id="@+id/first_linear_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="#fff">

        <ImageView
            android:id="@+id/cat_paw_image"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:contentDescription="@string/image_of_cat_paw"
            android:src="@drawable/cat_paw" />

        <ImageView
            android:id="@+id/lion_image"
            android:contentDescription="@string/image_of_lion"
            android:layout_width="match_parent"
            android:layout_height="212dp"
            android:src="@mipmap/lion"/>

        <TextView
            android:id="@+id/work_for_lions"
            android:text="@string/for_lion"
            android:contentDescription="@string/for_lion"
            android:textSize="30sp"
            android:textColor="#111"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:layout_marginBottom="10dp"/>

    </LinearLayout>



    <LinearLayout
        android:id="@+id/second_linear_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="#fff"
        android:layout_below="@id/first_linear_layout">

        <ImageView
            android:id="@+id/location_logo"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:contentDescription="@string/location_logo"
            android:src="@drawable/location_logo"
            android:layout_weight="1"/>

        <TextView
            android:id="@+id/first_text_view_in_second_linear_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/where_is"
            android:textColor="#111"
            android:textSize="25sp"
            android:layout_marginTop="5dp"
            android:layout_weight="1"/>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/third_linear_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="#fff"
        android:layout_below="@id/second_linear_layout">

        <ImageView
            android:id="@+id/time"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:contentDescription="@string/time_image"
            android:src="@drawable/time"
            android:layout_marginLeft="25dp"/>

        <TextView
            android:id="@+id/first_text_view_in_third_linear_layout"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="@string/what_the_time"
            android:textSize="25sp"
            android:textColor="#111"
            android:textAlignment="center"/>
    </LinearLayout>



</RelativeLayout> 

Примечание: я новичок в разработке для Android.

1 Ответ

0 голосов
/ 17 октября 2018

При использовании Относительного макета необходимо указать положения линейных макетов относительно Относительного макета или друг относительно друга, см. Относительный макет документа .Или используйте Linear Layout в качестве базы Linear Layout doc .

Или даже посмотрите на ConstraintLayout

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...