Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to align parent bottom in android linear layout?

I have a linearlayout

and I want to create at the bottom of it a slice.

I know there are some options, but I'm a bit confused

1) android:layout_gravity:"bottom" --> this doesn't work for me for some reason.

2) android:gravity_weight="0" and give the sibling before it android:gravity_weight:"1"

3) android:height="wrap_content" and give the sibling before it android:height:"match_parent"

I know how to do this using relativeLayout, but I want to practice linearLayout

what would you suggest?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/blue_bg"
    android:orientation="vertical" >

   <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="5dp"
        android:src="@drawable/signup_illu_why" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=""
        android:orientation="horizontal" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/signup_skip_icon" />

</LinearLayout>
like image 934
Elad Benda Avatar asked Dec 17 '13 11:12

Elad Benda


People also ask

How do you align at the bottom of relative layout?

If you have a relative layout that fills the whole screen you should be able to use android:layout_alignParentBottom to move the button to the bottom of the screen.

How do I fix the bottom layout on my android?

You can set the layout_height="0dp" of your header, footer and ScrollView and define a layout_weight . Just play around with the values until you find out which works best. The resulting heights of header and footer would dynamically change with the screensize.

How do you align a linear layout?

To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1" .

How do you align buttons in relative layout?

How do you align buttons in relative layout? The 2 buttons are placed below the TextView having id textView. This is done by using the android:layout_below="@+id/textView" attribute in both the Button tags.


2 Answers

<LinearLayout
    android:orientation="vertical"
                              ... >

    <Space
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <SomeViewThatNeedsGoBottom
                             ... />

</LinearLayout>
like image 89
Andrew Avatar answered Oct 29 '22 21:10

Andrew


Actually, you can set the parent element's gravity to bottom

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/blue_bg"
    android:orientation="vertical"
    android:gravity="bottom" >

   <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="5dp"
        android:src="@drawable/signup_illu_why" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=""
        android:orientation="horizontal" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/signup_skip_icon" />

</LinearLayout>
like image 30
Rick Royd Aban Avatar answered Oct 29 '22 21:10

Rick Royd Aban