android - 底部按钮栏与 Listview 的最后一个元素重叠!

标签 android listview checkbox buttonbar

我有一个 ListView ,它是 Activity 的一部分。我希望用户可以选择批量删除 ListView 中的项目,因此当他从菜单中选择相应的选项时,每个列表项旁边都会有一个复选框。当用户单击任何复选框时,按钮栏将从底部向上滑动(如在 gmail 应用程序中)并单击删除按钮删除所选项目,但是单击栏上的取消按钮将取消选中所有已选中的项目。

这是我的页面layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"    
    android:background="@android:color/transparent"
    >

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    >

    <LinearLayout
      android:id="@+id/list_area"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1"  
      >
      <ListView
          android:id="@+id/mylist"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:background="@android:color/transparent" 
          android:drawSelectorOnTop="false"
          android:layout_weight="1"
      />

      <TextView
        android:id="@+id/empty_list_message"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#FFFFFF"
        android:layout_gravity="center_vertical|center_horizontal"
        android:text="@string/msg_for_emptyschd"
        android:layout_margin="14dip"
        android:layout_weight="1"
         />
  </LinearLayout>

  <RelativeLayout
    android:id="@+id/bottom_action_bar"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/schedule_bottom_actionbar_border"
    android:layout_marginBottom="2dip"
    android:layout_gravity="bottom"
    android:visibility="gone"
    >    
    <Button
        android:id="@+id/delete_selecteditems_button"
        android:text="Deleted Selected"
        android:layout_width="140dip"
        android:layout_height="40dip"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="3dip"
        android:layout_marginTop="3dip"
    />

    <Button
    android:id="@+id/cancel_button"
        android:text="Cancel"
        android:layout_width="140dip"
        android:layout_height="40dip"
        android:layout_alignParentRight="true"
        android:layout_marginRight="3dip"
        android:layout_marginTop="3dip"
    />    
     </RelativeLayout>    
   </FrameLayout>        
</LinearLayout>

到目前为止,我已经完成了所有工作,除了当底部栏在选中复选框时变得可见时,它与列表的最后一个元素重叠。所有其他列表项都可以向上滚动,但您不能向上滚动列表的最后一项,因此用户无法选择该项目(如果他打算这样做)。这是 screenshot of the overlap .

我曾尝试使用 ListView 页脚选项,但它会将栏附加到列表的末尾,而不是将其固定在屏幕底部。有没有一种方法可以“提高” ListView ,以免发生重叠? 顺便说一句,我已经尝试将底部边距添加到 ListView 本身,或者在使按钮栏可见之前包装 ListView 的 LinearLayout,但它引入了其他错误,例如单击一个复选框会检查 ListView 中的另一个复选框。

最佳答案

没有对此进行测试,但我很确定是 FrameLayout 导致了这个 :)。因为 FrameLayout 并不关心你给它的“权重”。 FrameLayout 只是将您插入的 View 放在彼此的前面。你给的第二个,你说 android:layout_gravity="bottom"这使得它在底部对齐。但就在 ListView 的前面。删除 FrameLayout,我认为它应该可以工作。

像这样尝试:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@android:color/transparent">

    <LinearLayout android:id="@+id/list_area"
        android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1">
        <ListView android:id="@+id/mylist" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:background="@android:color/transparent"
            android:drawSelectorOnTop="false" android:layout_weight="1" />

        <TextView android:id="@+id/empty_list_message"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:textColor="#FFFFFF" android:layout_gravity="center_vertical|center_horizontal"
            android:text="@string/msg_for_emptyschd" android:layout_margin="14dip"
            android:layout_weight="1" />
    </LinearLayout>

    <RelativeLayout android:id="@+id/bottom_action_bar"
        android:orientation="horizontal" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:background="@drawable/schedule_bottom_actionbar_border"
        android:layout_marginBottom="2dip"
        android:visibility="gone">
        <Button android:id="@+id/delete_selecteditems_button"
            android:text="Deleted Selected" android:layout_width="140dip"
            android:layout_height="40dip" android:layout_alignParentLeft="true"
            android:layout_marginLeft="3dip" android:layout_marginTop="3dip" />
        <Button android:id="@+id/cancel_button" android:text="Cancel"
            android:layout_width="140dip" android:layout_height="40dip"
            android:layout_alignParentRight="true" android:layout_marginRight="3dip"
            android:layout_marginTop="3dip" />
    </RelativeLayout>

</LinearLayout>

关于android - 底部按钮栏与 Listview 的最后一个元素重叠!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4601939/

相关文章:

android为首选项屏幕设置分隔符填充

Android:notifyDataSetChanged()在方向改变后不更新 ListView

vb.net - ListView AutoReziseColumns 不起作用

android - 使用 CursorAdapter 维护 ListView 中的复选框状态

html - 你能在没有 JavaScript 的情况下在 HTML 中实现 "select all"复选框吗?

android - XING - 如何在 Android 和 iOS 上深度链接两者?

android - 我应该只使用 fragment 还是 Activity 和 fragment 的组合?

Android - 将 AppWidgets 添加到 Activity

android - 动态删除 View 或覆盖 View Android

javascript - 反转复选框值,以便在模型中检查为 false