Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.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 ScrollView在其下方保留重叠的项目_Android_Xml_Button_Scrollview - Fatal编程技术网

Android ScrollView在其下方保留重叠的项目

Android ScrollView在其下方保留重叠的项目,android,xml,button,scrollview,Android,Xml,Button,Scrollview,我有一个滚动视图,下面有两个水平对齐的按钮。我希望按钮A)在scrollview没有填满整个窗口时位于窗口底部,B)在scrollview大于窗口时位于其下方 目前,当scrollview没有填满整个窗口时,按钮会成功地放置在屏幕底部,但当scrollview的数据太多而无法放入窗口时(例如,当手机转到横向视图时),scrollview的数据会重叠在按钮上 我很难理解如何通过使用XML同时满足这两个条件。也许我别无选择,只能引入一些编程检查?无论如何,我的代码如下: <?xml versi

我有一个滚动视图,下面有两个水平对齐的按钮。我希望按钮A)在scrollview没有填满整个窗口时位于窗口底部,B)在scrollview大于窗口时位于其下方

目前,当scrollview没有填满整个窗口时,按钮会成功地放置在屏幕底部,但当scrollview的数据太多而无法放入窗口时(例如,当手机转到横向视图时),scrollview的数据会重叠在按钮上

我很难理解如何通过使用XML同时满足这两个条件。也许我别无选择,只能引入一些编程检查?无论如何,我的代码如下:

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

    <TextView android:id="@+id/groupHeader"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="20dp"
        android:textColor="#000000"
        android:textSize="25sp"
        android:text="@string/groupHeader" />     


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/groupHeader" >

        <LinearLayout
            android:layout_gravity="right"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/groupCreate" >
        </LinearLayout>
    </ScrollView>

    <Button
        android:id="@+id/groupcreate_button_new"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="5dp"
        android:text="@string/groupcreate_button_new" />

    <Button
        android:id="@+id/groupcreate_button_next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="5dp"
        android:layout_marginRight="5dp"
        android:text="@string/groupcreate_button_next" />

</RelativeLayout>

感谢您事先提供的一切帮助

编辑:

我可能应该提到,所讨论的ScrollView中的LinearLayout“groupCreate”被创建为空,但立即以编程方式添加了视图,这导致它占用空间,有时会溢出。

检查ScrollView的属性。Romain Guy已经很好地演示了它的用法。

试试这个xml

我对您的xml做了一些更改,包括id和其他东西,只是为了在我的设备上进行测试。 以后你可以根据自己的情况改变

<LinearLayout 
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:background="#FFFFFF"
       android:orientation="vertical">

    <TextView
        android:id="@+id/groupHeader"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:gravity="center"
        android:text="Group Header"
        android:textColor="#000000"
        android:textSize="25sp" />

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

        // You can put other View inside this scrollview

    </ScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Button
            android:id="@+id/groupcreate_button_new"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New" />

        <View
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <Button
            android:id="@+id/groupcreate_button_next"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Next" />

    </LinearLayout>

</LinearLayout>

//您可以在此滚动视图中放置其他视图

希望这能解决你的问题。

我自己也遇到了这个问题。@A.R的解决方案是可行的,但我觉得缺少一点解释。您必须使用LinearLayout才能将android:layout\u weight添加到子视图中,这会产生所有的“魔力”。将android:layout_weight=1添加到两个视图将强制android渲染两个视图,并排除重叠。 例如:



试着使用它,让我知道它是否符合您的要求。这就像一种魅力。非常感谢=)编辑:请原谅我的耽搁,我一发布这个消息就不得不关掉我的笔记本电脑。另外一个想法是:你能帮助我理解为什么这会起作用,而不是我最初所经历的行为吗?我更愿意学习而不是盲目地实现,我相信你们会理解的。实际上你们在UI中使用相对布局作为父视图。虽然使用相对布局没有坏处,但如果您能够处理它,它会很漂亮。相对布局维护父视图和子视图之间的关系。说到底部的两个按钮,实际上它们在父视图(包括滚动视图)的顶部对齐。因此,您的按钮不关心滚动视图占用的空间,它们将保留在屏幕底部。如果我误解了您的注释查询,请原谅。我对此进行了研究,但只是添加了一个“fillViewPort=”true“我没有耍花招;我想我必须移动ScrollView中的所有其他视图。这可能有效,但我尝试了上面的答案,它仍然有效。羞耻,我希望有一个简单的答案,就像换国旗一样。感谢=)要使用
fillViewPort
属性,您可能还需要包括至少一个视图(包含内容或空间隔
视图
),该视图与Romain一样在
线性布局中使用权重。事实上,后者似乎就是公认的答案。我希望给你指出正确的方向,这样你就可以仔细阅读细节,而不是断章取义地给出完整的答案。理解并感谢。我仍然不能始终可靠地预测XML将如何显示,这就是为什么我试图更好地理解这里发生了什么以及为什么。
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/groupcreate_button_new"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

</LinearLayout>