Android layout 将线性布局与底部对齐

Android layout 将线性布局与底部对齐,android-layout,android-linearlayout,Android Layout,Android Linearlayout,我有一个布局,我希望最后一个线性布局在最底部对齐。我试图设置重力和android:layout_marginbottom=0dp,但两个都没有将其与底部对齐 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/item_detail_container" android:l

我有一个布局,我希望最后一个
线性布局在最底部对齐。我试图设置重力和android:layout_marginbottom=0dp
,但两个都没有将其与底部对齐

<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>**

**
**

你必须使用
android:layou gravity
,而不是
android:gravity


layout\u gravity
指定相对于父级的重力,
gravity
控制内容在视图本身中的位置。

您必须使用
android:layout\u gravity
来完成此操作,而不是
android:gravity

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>

layout\u gravity
指定相对于父级的重力,
gravity
控制内容在视图本身中的位置。

应将相对布局作为线性布局的内部布局。比如这个例子。我希望它对你有用。
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>
您应该将相对布局作为线性布局的内部布局。比如这个例子。我希望它对你有用。

工作起来很有魅力。非常感谢你,工作很有魅力。非常感谢你。