Android 如何修复Listview项目末尾的按钮是否已完成?

Android 如何修复Listview项目末尾的按钮是否已完成?,android,listview,android-listview,Android,Listview,Android Listview,我试图在listview的末尾显示Pastentry按钮,而不是屏幕的末尾,但输出仅为listview,如果列表项更多,则显示按钮不显示,即listview必须滚动 我正在相对布局中编写此代码只需将按钮用作ListView页脚即可。这样,它将成为ListView的一部分,您可以向下滚动到它。将它放在相对布局中,例如下面的代码中给出的android:layout_over=“@+id/linear”这将把您的ListView放在其他布局之上,只需将ExpandableListView替换为List

我试图在listview的末尾显示Pastentry按钮,而不是屏幕的末尾,但输出仅为listview,如果列表项更多,则显示按钮不显示,即listview必须滚动
我正在相对布局中编写此代码

只需将按钮用作ListView页脚即可。这样,它将成为ListView的一部分,您可以向下滚动到它。

将它放在相对布局中,例如下面的代码中给出的android:layout_over=“@+id/linear”这将把您的ListView放在其他布局之上,只需将ExpandableListView替换为ListView即可

<ListView
    android:id="@+id/listContact"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:headerDividersEnabled="true"
    android:footerDividersEnabled="true"
    android:dividerHeight="10dp" 
    android:background="@drawable/background"
    android:divider="@drawable/background"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:fastScrollEnabled="true"
    android:scrollingCache="true"
    >
</ListView>

<Button
        android:id="@+id/btnContactPostYourEnquiry"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="POST YOUR ENQUIRY"
        android:background="@drawable/contact_post" 
        android:textColor="@color/White"
        android:layout_margin="10dp"
        android:layout_below="@+id/listContact"/>

通过编程设置列表视图的高度

例如

LinearLayout.LayoutParams LayoutParams=新的LinearLayout.LayoutParams( LayoutParams.MATCH_父项,您的_数组.size()*120)


nd在xml中添加按钮在线性布局中的bellow listview

我通过添加列表页脚视图来解决这个问题

layout_contact_list.xml

 <RelativeLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:background="#000000"
       android:orientation="horizontal" >
  <ExpandableListView
        android:id="@+id/lvExp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:cacheColorHint="#00000000"
        android:layout_above="@+id/linear"
        android:groupIndicator="@null" />

    <LinearLayout
        android:id="@+id/linear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:weightSum="1"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:orientation="horizontal" >
</LinearLayout>
    </RelativeLayout>

删除
RelativeLayout
将您的
ListView
按钮
放在
FrameLayout
中,并将按钮
重力设置为
Bottom
下拉投票人提及下拉投票的原因将按钮作为页脚添加到listviewalignParentBottom中对于按钮,我正在尝试的框架布局按钮为display底部屏幕不是ListView的底部我收到一个错误,自定义适配器无法设置为ExpandableListView将ExpandableListView更改为xmlExpandableListView中的ListView我在我的项目中使用它对您没有用,如果您正在使用listview继续使用它我的问题是我想在listview底部显示按钮,而不是屏幕底部。在布局中添加按钮,但设置其可见性已消失,然后在最后一个元素上计算列表中的元素数设置所有其他视图可见性已消失并使按钮可见谢谢我的问题已由AddIn解决footerView到列表如果它解决了您的问题,您介意将其标记为解决方案吗?这样一来,人们更容易访问此站点。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="fill_vertical" 
android:layout_marginBottom="@dimen/action_button" >

<ListView
    android:id="@+id/listContact"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/background"
    android:divider="@drawable/background"
    android:dividerHeight="10dp"
    android:fastScrollEnabled="true"
    android:footerDividersEnabled="true"
    android:headerDividersEnabled="true"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:scrollingCache="true" >

</ListView>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<Button
        android:id="@+id/btnContactPostYourEnquiry"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="POST YOUR ENQUIRY"
        android:background="@drawable/contact_post" 
        android:textColor="@color/White"
        android:layout_margin="10dp"
        android:padding="10dp"
        android:layout_gravity="center_horizontal"
        />
    ListView list_Contact=(ListView)findViewById(R.id.listContact);

    FrameLayout footerLayout = (FrameLayout) getLayoutInflater().inflate(R.layout.contact_footer_view,null);
    Button btnPostYourEnquiry = (Button) footerLayout.findViewById(R.id.btnContactPostYourEnquiry);
    list_Contact.addFooterView(footerLayout);