mornindew
mornindew

Reputation: 2221

Align Linear Layout to the bottom

I have a layout and I want the last LinearLayout to be aligned on the very bottom. I attempted to set the gravity and the android:layout_marginbottom=0dp and neither one seems to align it to the bottom.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_detail_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".ItemDetailActivity" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#000000"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="154dp" >

        <ImageView
            android:id="@+id/albumArt"
            android:layout_width="140dp"
            android:layout_height="138dp"
            android:src="@drawable/stealyourface" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="fill_horizontal|center"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/artistName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:paddingLeft="@dimen/TwentyPixels"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="#E6E6E6" />

            <TextView
                android:id="@+id/showLocation"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="@dimen/TwentyPixels"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#E6E6E6" />

            <TextView
                android:id="@+id/showDate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="@dimen/TwentyPixels"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#E6E6E6" />

            <TextView
                android:id="@+id/runningSong"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="@dimen/TwentyPixels"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="#E6E6E6" />
        </LinearLayout>

        <TextView
            android:id="@+id/currentlyPlaying"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="@dimen/TwentyPixels"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#E6E6E6" />
    </LinearLayout>

    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_width="match_parent"
        android:layout_height="214dp"
        android:background="#000000" >

        <LinearLayout
            android:id="@+id/songList"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
        </LinearLayout>
    </ScrollView>

    <!-- Player Buttons -->

    **<LinearLayout
        android:id="@+id/LinearLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        android:orientation="horizontal" 
        android:layout_marginBottom="0dp">
        <RelativeLayout
            android:layout_width="320dp"
            android:layout_height="wrap_content"
            android:background="@layout/rounded_corner"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:paddingLeft="10dp"
            android:paddingRight="10dp" >
            <!-- Previous Button -->
            <!-- Backward Button -->
            <!-- Play Button -->
            <ImageButton
                android:id="@+id/btnPlay"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/btnNext"
                android:layout_centerHorizontal="true"
                android:layout_centerInParent="true"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@+id/btnBackward"
                android:background="@null"
                android:src="@drawable/btn_play" />
            <!-- Forward Button -->
            <!-- Next Button -->
            <ImageButton
                android:id="@+id/btnPrevious"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/btnPlay"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:background="@null"
                android:src="@drawable/btn_previous" />
            <ImageButton
                android:id="@+id/btnBackward"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/btnPrevious"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@+id/btnPrevious"
                android:background="@null"
                android:src="@drawable/btn_backward" />
            <ImageButton
                android:id="@+id/btnNext"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="false"
                android:layout_alignTop="@+id/btnForward"
                android:layout_centerVertical="true"
                android:layout_marginLeft="16dp"
                android:layout_toRightOf="@+id/btnForward"
                android:background="@null"
                android:src="@drawable/btn_next" />
            <ImageButton
                android:id="@+id/btnForward"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@+id/btnPlay"
                android:background="@null"
                android:src="@drawable/btn_forward" />
        </RelativeLayout>
    </LinearLayout>
</LinearLayout>**

Upvotes: 1

Views: 15931

Answers (2)

Anil Singhania
Anil Singhania

Reputation: 845

You should take a relative layout as inner layout of linear layout. Like this example. I hope its useful for you. 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/mainact"
    android:weightSum="6" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_marginLeft="10dp"
        android:layout_weight="1"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/imageView9"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:clickable="true"
                android:onClick="func"
                android:src="@drawable/somnath" />

            <ImageView
                android:id="@+id/imageView20"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:clickable="true"
                android:onClick="func"
                android:src="@drawable/ghrishneshwar" />
        </RelativeLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:layout_marginLeft="10dp"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="fill_parent" >

            <ImageView
                android:id="@+id/imageView10"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginTop="10dp"
                android:clickable="true"
                android:onClick="func"
                android:src="@drawable/mallikarjun" />

            <ImageView
                android:id="@+id/imageView19"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="10dp"
                android:clickable="true"
                android:onClick="func"
                android:src="@drawable/kedarnath" />
        </RelativeLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:layout_marginLeft="10dp"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <ImageView
                android:id="@+id/imageView11"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginTop="20dp"
                android:clickable="true"
                android:onClick="func"
                android:src="@drawable/mahakaleshwar" />

            <ImageView
                android:id="@+id/imageView18"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="20dp"
                android:clickable="true"
                android:onClick="func"
                android:src="@drawable/trayambkeshwar" />
        </RelativeLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:layout_marginLeft="10dp"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <ImageView
                android:id="@+id/imageView12"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginTop="50dp"
                android:clickable="true"
                android:onClick="func"
                android:src="@drawable/omkareshwar" />

            <ImageView
                android:id="@+id/imageView17"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="50dp"
                android:clickable="true"
                android:onClick="func"
                android:src="@drawable/kashim" />
        </RelativeLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:layout_marginLeft="5dp"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <ImageView
                android:id="@+id/imageView13"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginTop="90dp"
                android:clickable="true"
                android:onClick="func"
                android:src="@drawable/vaidyanath" />

            <ImageView
                android:id="@+id/imageView16"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="90dp"
                android:clickable="true"
                android:onClick="func"
                android:src="@drawable/nageshwar" />
        </RelativeLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="20dp"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <ImageView
                android:id="@+id/imageView14"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginTop="170dp"
                android:clickable="true"
                android:onClick="func"
                android:src="@drawable/bhimashankar" />

            <ImageView
                android:id="@+id/imageView15"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="170dp"
                android:clickable="true"
                android:onClick="func"
                android:src="@drawable/rameshwaram" />
        </RelativeLayout>
    </LinearLayout>

</LinearLayout>

Upvotes: 0

brillenheini
brillenheini

Reputation: 5453

You have to use android:layout_gravity to do that, not android:gravity.

http://developer.android.com/reference/android/widget/FrameLayout.html

layout_gravity specifies the gravity in respect to the parent, gravity controls the placement of the content in the view itself.

Upvotes: 6

Related Questions