Amandeep Singh
Amandeep Singh

Reputation: 3840

Place LinearLayout at bottom of another LinearLayout

I am trying to place LinearLayout containing gridview at the bottom. Please suggest what can be done.

Below is my XML code :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/parentRelativeView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/darkgreen"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/txtEquation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/darkorange"
        android:gravity="center"
        android:text="2+2=?"
        android:textColor="@color/white"
        android:textSize="40dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/txtOutput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/darkpurple"
        android:gravity="center"
        android:textColor="@color/white"
        android:textSize="28dp"
        android:textStyle="bold" />

    <com.github.lzyzsd.circleprogress.DonutProgress
        android:id="@+id/donut_progress"
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:layout_below="@+id/txtOutput"
        android:layout_gravity="center"
        android:gravity="center"
        android:textColor="@color/white"
        custom:donut_finished_color="#30b8f2"
        custom:donut_progress="01"
        custom:donut_text_size="50dp" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_weight="0"
        android:background="@color/white"
        android:baselineAligned="false">

        <GridView
            android:id="@+id/numberGridView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="0.4dp"
            android:background="@color/white"
            android:horizontalSpacing="0.4dp"
            android:numColumns="@integer/grid_rows"
            android:stretchMode="columnWidth"
            android:verticalSpacing="0.4dp" />
    </LinearLayout>
</LinearLayout>

Upvotes: 0

Views: 585

Answers (1)

Sebastian Pakieła
Sebastian Pakieła

Reputation: 3029

There is no way you can align some items to top and others to bottom in LinearLayout. We have RelativeLayout for purposes like this. With RelativeLayout you can align anything to anything so I recommend you to use it.

Upvotes: 1

Related Questions