Ahmed Mohsen
Ahmed Mohsen

Reputation: 433

How to align 2 views in one layout , so one at most top and the other one on the most bottom

I have a linear layout on my view

it has 2 view inside it , one "button" and one "frameLayout"

making the gravity : "top" for the parent layout , positioning the 2 inside views on the most top

making the gravity : "bottom" for the parent layout , positioning the 2 inside views on the most bottom

how to set the button on the most bottom , and the "frameLayout" on the most top

my current codes :

<?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:background="#FFF"
    android:minWidth="25px"
    android:minHeight="25px"
    android:gravity="bottom">
    <FrameLayout
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/frameLayout1"
        android:layout_gravity="top">
        <ListView
            android:minWidth="25px"
            android:minHeight="25px"
            android:id="@+id/notifiers"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </FrameLayout>
    <Button
        android:text="+"
        android:id="@+id/newTask"
        android:background="#13F"
        android:textSize="20pt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom" />
</LinearLayout>

Upvotes: 0

Views: 151

Answers (3)

hiashutoshsingh
hiashutoshsingh

Reputation: 1020

check out this code i have just edited your code it works perfectly as you desire!

<?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:background="#FFF"
    android:minWidth="25px"
    android:minHeight="25px"
    android:gravity="bottom">
    <FrameLayout
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_weight="9"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:id="@+id/frameLayout1"
        android:layout_gravity="top">
        <ListView
            android:minWidth="25px"
            android:minHeight="25px"
            android:id="@+id/notifiers"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </FrameLayout>
    <FrameLayout
        android:layout_gravity="center_horizontal"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="0dp">
    <Button

        android:text="+"
        android:id="@+id/newTask"
        android:background="#13F"
        android:textSize="20pt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom" />
    </FrameLayout>
</LinearLayout>

Upvotes: 3

Yousef khan
Yousef khan

Reputation: 3214

You can use weight to achieve what you want.
Add android:layout_weight="1"
in the FrameLayout

Upvotes: 0

Ak9637
Ak9637

Reputation: 990

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFF"
    android:minWidth="25px"
    android:minHeight="25px"
    android:gravity="bottom">
    <FrameLayout
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_alignParentTop="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/frameLayout1"
        android:layout_gravity="top">
        <ListView
            android:minWidth="25px"
            android:minHeight="25px"
            android:id="@+id/notifiers"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </FrameLayout>
    <Button
        android:text="+"
        android:id="@+id/newTask"
        android:background="#13F"
        android:textSize="20pt"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom" />
</RelativeLayout>

use relative layout for your purposes, it allow much more control over relative positions

Upvotes: 2

Related Questions