alignparentbottom用于scrollview内的relativelayout

时间:2014-09-22 19:40:57

标签: android scrollview

我正在尝试在屏幕底部放置一些内容(在本例中为id为'bottomcontent'的LL),当用户开始滚动时,我想在其底部显示更多内容。任何想法如何做到这一点?我有以下代码,但没有滚动,因为'bottomcontent'下面的LL得到height = 0

Here is the code:
<ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MyActivity"
        android:background="@android:color/transparent"
        android:fillViewport="true"
        android:layout_alignParentTop="true">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <!-- I expect this to occupy one full screen, since its child is asking for align parent bottom = true-->
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@android:color/transparent"
                android:id="@+id/top">
                <LinearLayout
                    android:id="@+id/bottomcontent"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/holo_green_dark"
                    android:layout_alignParentBottom="true"
                    >

                    <TextView
                        android:text="@string/hello_world"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:background="@android:color/holo_red_light"
                        />
                </LinearLayout>
            </RelativeLayout>
            <!-- When user scrolls, I expect this linear layout to be seen. But I get its height to be zero, so no scrolling-->
            <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"
                >


                <TextView
                    android:text="hello_world hello_world hello_world hello_world hello_world hello_world hello_world "
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:background="@android:color/holo_blue_dark"
                    />
            </LinearLayout>

        </LinearLayout>
    </ScrollView>

1 个答案:

答案 0 :(得分:3)

我从你的问题中得到的是你想要一个滚动视图但是你想要一个LL显示在屏幕的底部。即使用户滚动,LL应显示在底部,对吗?您可以尝试以下布局。

<RelativeLayout>
    <ScrollView>
        <RelativeLayout>
            <!--...everything you want to show in scrollview -->
        </RelativeLayout>
    </ScrollView>

    <LinearLayout
        <!--...your layout which you want to always show at bottom.-->
        android:layout_alignParentBottom="true">
    </LinearLayout>

</RelativeLayout>

这将使LL停滞在底部,其余的将滚动。