按钮需要在底部

Button needs to be on the bottom

没有Scrollview,Button在屏幕底部,这是我们想要的结果。但是一旦我添加了滚动视图,按钮就不再位于屏幕底部了。

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

试试这个

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

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

    android:fillViewport="true"

ScrollView 添加另一个属性:

android:fillViewport="true"

这样 ScrollView 高度将符合 child 的 android:layout_height="match_parent" 属性

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

app:layout_behavior = "@string/appbar_scrolling_view_behavior"

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

 android:layout_alignParentBottom = "true"
 android:layout_centerHorizontal = "true"