Java 使用列表视图滚动布局

Java 使用列表视图滚动布局,java,android,listview,android-listview,scrollview,Java,Android,Listview,Android Listview,Scrollview,我的问题是我的listview在AbsoluteLayout上工作得很好,但是底部的按钮没有显示出来!我放置了一个带有所有项目(文本视图、按钮等)的绝对布局的scrollview,在scrollview之外我放置了listview,这也不起作用,只是滚动按钮,但listview只是移动了一点,我如何放置scrollview来查看按钮上的按钮并使listview工作? 我的XML: 您使用的是绝对布局,这意味着,从文档中可以看出: 一种布局,用于指定其子对象的精确位置(x/y坐标) 因此,如果

我的问题是我的listview在AbsoluteLayout上工作得很好,但是底部的按钮没有显示出来!我放置了一个带有所有项目(文本视图、按钮等)的绝对布局的scrollview,在scrollview之外我放置了listview,这也不起作用,只是滚动按钮,但listview只是移动了一点,我如何放置scrollview来查看按钮上的按钮并使listview工作? 我的XML:



您使用的是绝对布局,这意味着,从文档中可以看出:

一种布局,用于指定其子对象的精确位置(x/y坐标)

因此,如果您没有看到按钮,那是因为它们位于设备屏幕边界之外。而且他们的位置是绝对的/固定的,所以他们无论如何都会留在那里


我建议更改为不同的布局。我不知道您正在构建什么样的应用程序,但绝对布局通常不是最佳选择

可能性第一:

 <?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="@color/background"
                android:clickable="true">


    <ListView
        android:id="@+id/allPaymentListView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/addNewPayment"

        android:layout_marginTop="10dp"></ListView>

    <Button
        android:id="@+id/addNewPayment"
        android:layout_width="match_parent"
        android:layout_height="@dimen/primary_button_height"
        android:layout_alignParentBottom="true"
        android:layout_margin="10dp"
        android:background="@drawable/blackbutton"
        android:text="@string/add_new_card"
        android:textColor="@color/light_blue"/>


</RelativeLayout>

在这种情况下,按钮将始终显示在页面底部的listview下方

第二种可能是向listview添加页脚:

在这种情况下,带有按钮的视图将是listview中的最后一个元素


不要使用绝对布局。它已被弃用,原因是应用程序无法按您的需要缩放到不同的屏幕大小。

您应该使用相对布局,按钮位于底部,列表视图位于按钮顶部


总的来说,绝对的布局是。除非您试图实现一个非常特定的目的,否则要避免布局。绝对定位元素被认为是一种反模式。要实现您所说的,RelativeLayout将是一个不错的选择。

使用
RelativeLayout
作为您的父视图,将您的按钮放在RelativeLayout的底部,将ParentBottom与true对齐,并将您的listview放在按钮上方..可以安全地说,将您的按钮放在线性布局中,将您的listview放在顶部,希望你能明白。抱歉,如果您不确定Android中的布局,请阅读文档。由于屏幕尺寸太多,所以使用相对布局至关重要!因此,您的gui设计是动态的,可以跨尽可能多的设备工作!阅读相关布局文档。。。我宁愿使用absolutelayout,因为我可以将项目移动到我想要的任何地方,但这现在不起作用,我已经将其更改为relative,它可以工作,我很难在该布局中移动项目,但至少它可以工作!,谢谢
 <?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="@color/background"
                android:clickable="true">


    <ListView
        android:id="@+id/allPaymentListView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/addNewPayment"

        android:layout_marginTop="10dp"></ListView>

    <Button
        android:id="@+id/addNewPayment"
        android:layout_width="match_parent"
        android:layout_height="@dimen/primary_button_height"
        android:layout_alignParentBottom="true"
        android:layout_margin="10dp"
        android:background="@drawable/blackbutton"
        android:text="@string/add_new_card"
        android:textColor="@color/light_blue"/>


</RelativeLayout>