Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 具有可滚动底部视图的正确方法_Android_Android Layout_Android Scrollview - Fatal编程技术网

Android 具有可滚动底部视图的正确方法

Android 具有可滚动底部视图的正确方法,android,android-layout,android-scrollview,Android,Android Layout,Android Scrollview,拥有可滚动底视图的正确方法是什么 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true"> <Li

拥有可滚动底视图的正确方法是什么

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/wrnTextP1"
        android:text="Ok , batatas  "/>

    <android.support.v4.widget.Space
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="1" />

    <Button
        style="@style/FullWidthButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Chega por hoje!" />
</LinearLayout>
在预览时,它看起来很好,但是当我在模拟器上运行它时,视图在这种情况下:按钮根本不在底部


我认为您误解了ScrollView的用途。ScrollView的LinearLayout子级与父级高度匹配。。。如果您的ScrollView与屏幕的高度相同,而LinearLayout与ScrollView的高度相同,则无需滚动任何内容。所有内容都是屏幕的大小

ScrollView的直接子级应该具有固定的高度(如2000dp)或使用wrap_内容

如果使用固定高度,则代码的其余部分可以工作;可以使用使用布局权重的空间元素将最后一个视图向下推到线性布局的底部。但是,如果您使用的是wrap_内容,这是不可能的,因为没有额外的空间供布局重量使用

取而代之的是,可以考虑将底部视图置于滚动视图之外。大概是这样的:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        ...

    </ScrollView>

    <Button
        style="@style/FullWidthButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Chega por hoje!" />

</LinearLayout>

你说的是哪个视图?按钮。。。我在想,这些图片是自我解释的。这个底部按钮是可滚动的还是只在底部,上面的内容是可滚动的?你需要使用“android:layout\u alignParentBottom=true”和RelativeLayout,而不是LinearLayout。为此,您可以使用布局\重力=底部。但在你的情况下,ScrollView`没有任何意义。如果您想拥有一个ScrollView并将一个按钮固定在底部,请使用RelativeLayout作为根布局,并将该按钮添加到相对布局中,设置alignParentBottom=true并将ScrollView作为子视图添加到根目录RelativeLayout@ArturSzymański此按钮应该是可滚动的很好的解释,但我使用的是fillViewPort=true的scrollview,无论如何都应该拉伸内容。当没有可用的滚动条或滚动条时,按钮应位于最底部