small
small

Reputation: 493

Layout bottom and rest of screen

I want to make a layout at the bottom of the screen to take as much height as it needs, and another layout at the rest of the screen - from top to the start of the other layout. But I dont know how to do it: here is what i did so far:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    android:background="@color/background_material_dark"
    tools:context="com.example.exercise2.myapplication.HangedMan">

    <LinearLayout
        android:layout_width="match_parent"
        android:id="@+id/viewLayout"
        android:gravity="center|center_horizontal"
        android:layout_height="wrap_content"
        android:orientation="vertical">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageView"
        android:src="@drawable/img0" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:id="@+id/mainLayout"
        android:layout_below="@+id/viewLayout"
        android:layout_height="wrap_content"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:orientation="vertical">
    </LinearLayout>
</RelativeLayout>

the layout that should be at the top is above the other layout as should be, but he doesnt get rest of the screen height

Upvotes: 1

Views: 360

Answers (1)

WISHY
WISHY

Reputation: 11999

Use

 android:layout_alignParentBottom="true"

To keep any any view/layout in the bottom of screen. This only works with relative layout.

An example fro you

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.app.LoginActivity">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+id/botLayout"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true">


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:id="@+id/textView2" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/textView3" />
</LinearLayout>

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:gravity="center"
    android:id="@+id/botLayout"
    android:layout_centerHorizontal="true">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/textView" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button" />
</LinearLayout>

Upvotes: 1

Related Questions