【问题标题】:how to fix button at end of Listview item are completed?如何修复 Listview 项目末尾的按钮已完成?
【发布时间】:2014-04-10 12:42:27
【问题描述】:
<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"/>

我尝试在列表视图的末尾而不是屏幕的末尾显示 PastEnqury 按钮,但输出只是列表视图,如果列表项更多,则不显示显示按钮,即列表视图必须滚动 我在相对布局中编写这段代码

【问题讨论】:

  • 删除RelativeLayoutListViewButton 放入FrameLayout 并将按钮Gravity 设置为Bottom
  • DownVoters 提及您投反对票的原因
  • 添加按钮作为列表视图的页脚
  • alignParentBottom 按钮为真
  • 我正在尝试框架布局按钮显示屏幕底部而不是 ListView 底部

标签: android listview android-listview


【解决方案1】:

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

【讨论】:

  • 感谢我的问题是通过将 footerView 添加到列表中解决的
  • 如果它解决了您的问题,您介意将其标记为解决方案吗?这样一来,访问此网站的人就更容易了。
【解决方案2】:

将它放在相对布局中,例如在android:layout_above="@+id/linear"下面的代码中给出,这会将您的列表视图置于其他布局之上,只需将 ExpandableListView 替换为 ListView

 <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>

【讨论】:

  • 我收到自定义适配器无法设置为 ExpandableListView 的错误
  • 在xml中将ExpandableListView改为ListView
  • ExpandableListView 在我的项目中被我使用过,它对你没用,如果你正在使用 listview 继续使用它
  • 我的问题是我想在 ListView 底部而不是屏幕底部显示按钮
  • 嘿,在您的布局中添加按钮,但设置其可见性消失然后计算最后一个元素列表中的元素数量设置所有其他视图可见性消失并使按钮可见
【解决方案3】:

以编程方式设置列表视图的高度

例如

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, your_array.size() * 120);

在 xml 中在线性布局中添加按钮波纹管列表视图

【讨论】:

    【解决方案4】:

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

    layout_contact_list.xml

    <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>
    

    contact_footer_view.xml

    <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"
            />
    

    mainActivity.java

        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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-26
      相关资源
      最近更新 更多