按钮需要在底部

时间:2016-10-20 10:14:03

标签: android android-layout android-scrollview

如果没有Scrollview,按钮位于屏幕的底部,这是所需的结果。但是一旦我添加了Scrollview,按钮就不再位于屏幕的底部了。

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

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

        <RelativeLayout
            android:id="@+id/scrollview_wrapper"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_marginTop="0dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_marginBottom="10dp"
                android:lines="1"
                android:gravity="center"
                android:textSize="16sp"/>

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

4 个答案:

答案 0 :(得分:1)

将另一个属性添加到ScrollView

android:fillViewport="true"

这种ScrollView身高会尊重孩子的android:layout_height="match_parent"属性

答案 1 :(得分:0)

试试这个

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

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


</ScrollView>


<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:layout_marginTop="0dp"
    android:gravity="center"
    android:lines="1"
    android:textSize="16sp" />

</RelativeLayout>  

答案 2 :(得分:0)

问题出在滚动视图中,只需将以下属性添加到滚动视图中即可。

    android:fillViewport="true"

答案 3 :(得分:0)

只需将滚动视图行为添加到滚动视图

即可
app:layout_behavior = "@string/appbar_scrolling_view_behavior"

并将代码添加到按钮xml文件

 android:layout_alignParentBottom = "true"
 android:layout_centerHorizontal = "true"
相关问题