horin
horin

Reputation: 1662

layout_gravity bottom not working

I am using the following XML to draw a layout with heading, subheading, image and button. Image takes all remaining space but at the end I set it to visibility = View.GONE and my button is not aligned to bottom. What am I doing wrong?

<?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"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingBottom="10dp"
    android:baselineAligned="false">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/kasel"
        android:id="@+id/txtChokeNext"
        android:textSize="20sp"
        android:gravity="center_horizontal"
        android:layout_marginTop="10dp"
        android:layout_gravity="top"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/kaselDesc"
        android:id="@+id/txtChokeNextDesc"
        android:gravity="center"
        android:layout_marginTop="10dp"
        android:textStyle="bold"
        android:layout_gravity="top"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:id="@+id/imgChokeDesc"
        android:src="@drawable/kasel"
        android:adjustViewBounds="true"
        android:baselineAlignBottom="false"
        android:cropToPadding="false"
        android:layout_weight="1" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/firstAidNext"
        android:id="@+id/buttonChokeNext"
        android:layout_marginTop="10dp"
        android:paddingLeft="10dp"
        android:paddingTop="20dp"
        android:paddingRight="10dp"
        android:paddingBottom="20dp"
        android:layout_gravity="bottom"
        />

</LinearLayout>

Thanks in forward

Upvotes: 0

Views: 674

Answers (2)

Thanos
Thanos

Reputation: 3665

You could change your layout to RelativeLayout and set this parameter to your Button:

android:layout_alignParentBottom="true"

You should also add the android:layout_below="..." in the subheader and image to place them one after the other (replace ... with the id of the element that should be above the element you're editing)

Upvotes: 1

msevgi
msevgi

Reputation: 4904

solution of the your problem

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/kasel"
            android:id="@+id/txtChokeNext"
            android:textSize="20sp"
            android:gravity="center_horizontal"
            android:layout_marginTop="10dp"
            android:layout_gravity="top" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/kaselDesc"
            android:id="@+id/txtChokeNextDesc"
            android:gravity="center"
            android:layout_marginTop="10dp"
            android:textStyle="bold"
            android:layout_gravity="top" />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:id="@+id/imgChokeDesc"
            android:src="@drawable/kasel"
            android:adjustViewBounds="true"
            android:baselineAlignBottom="false"
            android:cropToPadding="false"
            android:layout_weight="1" />
    </LinearLayout>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/firstAidNext"
        android:id="@+id/buttonChokeNext"
        android:layout_marginTop="10dp"
        android:paddingLeft="10dp"
        android:paddingTop="20dp"
        android:paddingRight="10dp"
        android:paddingBottom="20dp"
        android:layout_gravity="bottom" />

</LinearLayout>

Upvotes: 0

Related Questions