简体   繁体   English

滚动视图底部的Android按钮

[英]Android Buttons at the bottom in a scrollview

I have a ScrollView with a RelativeLayout. 我有一个带有RelativeLayout的ScrollView。 I'm gonna have 2 / 3 buttons at the bottom, but they wont stay at the bottom. 我将在底部有2/3个按钮,但它们不会停留在底部。 Can anyone see where i did things wrong? 谁能看到我在哪里做错了事?

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


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



        <Button
            android:layout_width="110dp"
            android:layout_height="wrap_content"
            android:text="@string/hjem"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"/>

        <Button
            android:layout_width="110dp"
            android:layout_height="wrap_content"
            android:text="@string/neste"
            android:layout_alignParentEnd="true"
            android:layout_alignParentBottom="true"/>


    </RelativeLayout>
</ScrollView>

if you check correctly the buttons are at the bottom of the relative layout. 如果您检查正确,则按钮位于相对布局的底部。 The problem is the scrollview that is not taking full screen. 问题是没有全屏显示的滚动视图。 Check this xml: 检查此xml:

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


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


        <Button
            android:layout_width="110dp"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:text="@string/hjem"/>

        <Button
            android:layout_width="110dp"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true"
            android:text="@string/neste"/>


    </RelativeLayout>
</ScrollView>

If you notice i have inserted the android:fillViewport="true" at scrollview 如果您注意到我在scrollview中插入了android:fillViewport =“ true”

just try to change the height attribute of relative layout to match_parent: 只需尝试将相对布局的height属性更改为match_parent即可:

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


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



        <Button
            android:layout_width="110dp"
            android:layout_height="wrap_content"
            android:text="@string/hjem"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"/>

        <Button
            android:layout_width="110dp"
            android:layout_height="wrap_content"
            android:text="@string/neste"
            android:layout_alignParentEnd="true"
            android:layout_alignParentBottom="true"/>


    </RelativeLayout>
</ScrollView>

使用android:fillViewPort =“ true” ....这会扩展布局以覆盖整个滚动视图...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM