Add Views in RelativeLayout

0

How about? I hope you can help me, I want to create a LinearLayout and a ScrollView within a RelativeLayout, I have an idea but the truth does not fit, I am somewhat confused about the dimensions MATCH_PARENT and WRAP_CONTENT, I attach an image to visualize my idea, thanks for your attention.

    
asked by Javier Irepan 05.06.2018 в 04:45
source

1 answer

1

match_parent - > The element occupies the total of its parent element.

wrap_content - > The element will expand only enough to contain the values / elements it contains.

To get what you want you must add the following code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:background="@color/color0"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <LinearLayout
        android:background="@color/color"
        android:layout_margin="8dp"
        android:id="@+id/llayout"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:orientation="vertical">
        <!--elementos-->
    </LinearLayout>
    <ScrollView
        android:background="@color/color1"
        android:layout_margin="8dp"
        android:layout_below="@+id/llayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:background="@color/color2"
            android:layout_margin="8dp"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <!--elementos-->
            <View
                android:layout_weight="1"
                android:layout_margin="8dp"
                android:layout_width="match_parent"
                android:layout_height="500dp"/>
        </LinearLayout>
    </ScrollView>
</RelativeLayout>

You will get the following:

It should be mentioned that at your first LinearLayout you must assign a static layout_height android:layout_height="200dp" in this case as an example I put 200dp but you will modify it according to your needs. besides eliminating the el% View in ScroollView > LinearLayout put only to note the organization of the elements.

    
answered by 14.06.2018 в 19:24