How to make LinearLayout stay at the bottom of the screen?

2

I have tried many things here to make my LinearLayout stand at the bottom of the screen but I can not do that. I need to do this with Linear which has the id="underneath" Anyone know?

Follow my xml:

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

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

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:text="Teste"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </ScrollView>

    <LinearLayout
        android:id="+id/embaixo"
        android:layout_gravity="end"
        android:gravity="end"
        android:padding="10dp"
        android:background="@color/colorAccent"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:scaleType="fitCenter"
            app:srcCompat="@drawable/marca_simplifica" />
    </LinearLayout>
</LinearLayout>

    
asked by anonymous 13.09.2017 / 14:12

2 answers

1

The linearlayout say that they respect a hierarchy, if they are horizontal then they will be allocated side by side, if they are vertical they will be allocated one underneath the other. The order is in accordance with the XML. Relativelayout, let's say you break this pattern and you can adapt other layouts according to your needs.

Here is an example of how to put a linearlayout on top and a bottom on a relativelayout:

<?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:id="@+id/top_linear_layout_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" >
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottom_linear_layout_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >
    </LinearLayout>
</RelativeLayout>
    
13.09.2017 / 14:28
0

You should include the android: layout_alignParentBottom="true" , but for this to work, you must be a RelativeLayout child:

    <RelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
             android:id="+id/embaixo"
             android:layout_alignParentBottom="true
             android:gravity="end"
             android:padding="10dp"
             android:background="@color/colorAccent"
             android:orientation="horizontal"
             android:layout_width="match_parent"
             android:layout_height="wrap_content">

             ...            

        </LinearLayout>

    </RelativeLayout>
    
13.09.2017 / 14:27