Android: put a textView in Linear Layout at the bottom of the screen

0

I just started studying with Android Studio and I tried all the sentences for my textView on bottom screen for LinearLayout , but so far nothing. How can I do it? Help !!!

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

    <TextView
        android:text="You're invited!"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white"
        android:textSize="54sp"
        android:background="#009688" />

    <TextView
        android:text="Bonfire at the beach"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white"
        android:textSize="34sp"
        android:background="#009688" />

    <ImageView
        android:src="@drawable/ocean"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop" />
</LinearLayout>
    
asked by Vero 17.04.2018 в 05:50
source

1 answer

0

First let's understand how a LinearLayout works

LinearLayout: Lists the elements in a row or column. It has the Views one after the other. Therefore the views 'in this case will be a TextView ' that we want to position in the lower part, should go in the last position defined in our xml.

  

We must also give all the available space and float it at the bottom.   We do this with these 2 lines ..

    android:layout_height="match_parent"
    android:gravity="bottom"

I leave the code of your xml with the textview at the bottom

<?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">
    <ImageView
        android:src="@drawable/ocean"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop" />
    <TextView
        android:text="You're invited!"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white"
        android:textSize="54sp"
        android:background="#009688" />
    <TextView
        android:text="Bonfire at the beach"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="bottom"
        android:textColor="@android:color/white"
        android:textSize="34sp"
        android:background="#009688" />
</LinearLayout>

And the result :

    
answered by 21.04.2018 в 09:39