RelativeLayout总是在底部

时间:2014-01-24 11:53:41

标签: java android xml

我正试图迫使RelativeLayout在屏幕底部保持始终,所以我写了这段代码。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:id="@+id/main"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <RelativeLayout
            android:id="@+id/myFirstLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <!-- other view here -->

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/mySecondLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/myFirstLayout" >

            <!-- Views -->

            <LinearLayout
                android:id="@+id/myLinearLayout"
                android:layout_width="fill_parent"
                android:layout_height="1dip"
                android:orientation="horizontal" >
            </LinearLayout>

            <!-- View here -->

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/layoutAtBottom"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_below="@+id/mySecondLayout" >

            <LinearLayout
                android:id="@+id/myLinearAtBottom"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:gravity="bottom"
                android:orientation="vertical" />
        </RelativeLayout>
    </RelativeLayout>

</ScrollView>

当我可以滚动(在这种情况下保持在底部)时,此代码有效但当我无法滚动布局时,它位于mySecondLayout的下方,但不在底部。为什么?我该如何解决?

3 个答案:

答案 0 :(得分:0)

删除android:layout_below="@+id/mySecondLayout",然后重试。

希望它有效

答案 1 :(得分:0)

从滚动视图中弹出底部线性,并将包裹的RelativeLayout取消为:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

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

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/myLinearAtBottom" >

        <RelativeLayout
            android:id="@+id/main"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <RelativeLayout
                android:id="@+id/myFirstLayout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >

                <!-- other view here -->

            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/mySecondLayout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/myFirstLayout" >

                <!-- Views -->

                <LinearLayout
                    android:id="@+id/myLinearLayout"
                    android:layout_width="fill_parent"
                    android:layout_height="1dip"
                    android:orientation="horizontal" >
                </LinearLayout>

                <!-- View here -->

            </RelativeLayout>
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>

答案 2 :(得分:0)

Use this layout.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <ScrollView
        android:id="@+id/main"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/layoutAtBottom" >

        <RelativeLayout
            android:id="@+id/myFirstLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <!-- other view here -->

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/mySecondLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/myFirstLayout" >

            <!-- Views -->

            <LinearLayout
                android:id="@+id/myLinearLayout"
                android:layout_width="fill_parent"
                android:layout_height="1dip"
                android:orientation="horizontal" >
            </LinearLayout>

            <!-- View here -->

        </RelativeLayout>
    </ScrollView>

    <RelativeLayout
        android:id="@+id/layoutAtBottom"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

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

</RelativeLayout>