底部的按钮栏重叠的ListView的最后一个元素! [英] Bottom button bar overlaps the last element of Listview!

查看:173
本文介绍了底部的按钮栏重叠的ListView的最后一个元素!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ListView这是一个活动的一部分。我希望用户拥有批量删除在ListView的项目选择,所以当他从菜单中选择相应的选项,每个列表项获得它旁边的复选框。当用户点击任何复选框,按钮栏是向上滑动从下(如Gmail应用程序),然后单击删除按钮删除选定的项目,但是点击取消栏上的按钮,将取消所有的检查项目。

I have a listview which is part of an Activity. I want user to have a choice for batch deleting the items in the listview, so when he chooses the corresponding option from the menu, every list item gets a checkbox next to it. When user clicks any checkbox, a button bar is to slide up from bottom (as in gmail app) and clicking delete button deletes the selected items, however clicking cancel button on the bar would uncheck all the checked items.

这是我的网页layout.xml:

This is my page 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>

到目前为止,我已经得到了一切,只是工作时,底部栏将变为一旦选中复选框可见,它重叠列表的最后一个元素。所有其他列表项可以滚动起来,但你不能向上滚动列表的最后一项,因此用户不能如他打算选择该项。这里是重叠的截图。

so far, I have got everything working except that when the bottom bar becomes visible upon checkbox selection, it overlaps the last element of the list. All other list items can be scrolled up, but you cant scroll up the very last item of the list, therefore user can not select that item if he intends to. Here is the screenshot of the overlap.

我已经使用了列表视图页脚选项尝试过,但追加栏到列表的末尾,而不是保持它固定在屏幕的底部。有没有一种方法,我可以养列表视图足以使重叠不会发生?
顺便说一句,我已经尝试添加底边距到ListView本身,还是的LinearLayout权使得按钮栏可见之前包裹的列表视图,但它引入其他错误如单击一个复选框检查一些列表视图另一个复选框。

I have tried using the listview footer option, but that appends the bar to the end of the list instead of keeping it fixed at the bottom of the screen. Is there a way I could "raise" the listview enough so that the overlap wont happen?? BTW, I have already tried adding the bottom-margin to the listview itself, or the LinearLayout wrapping the listview right before making the button-bar visible, but it introduces other bugs like clicking one checkbox checks some another checkbox in listview.

推荐答案

好像我已经解决了奇怪的复选框的行为问题。首先,问题发生,因为一旦被列表视图大小,它重绘自身,因此getView()被再次呼吁所有可见的列表项。由于我使用的是ViewHolder,视图是越来越重用,现在看来似乎导致相同的复选框来获得其他一些列表项再次重用。因此,因此,当我点击一个复选框,得到了一些点击复选框等代替。因为,这个调用刷新列表视图只发生时正在调整列表,列表中得到调整仅标志着列表中的复选框,当没有其他复选框被标记,这个问题不会再次第一个复选框已经被标记后出现。

Seems like I have solved the problem of strange checkbox behavior. First, the problem was happening because as soon as the listview gets resized, it redraws itself, therefore getView() gets called again for all the visible list items. Since I am using a ViewHolder, and the view is getting reused, it seems like it causes the same checkbox to get reused again for some other list item. So therefore, when I was clicking one checkbox, some other checkbox was getting clicked instead. Since, this call to refresh the listview was only happening when the list was being resized, and list was getting resized only on marking a checkbox in list when no other checkbox was marked, this problem does not appear again after the first checkbox has been marked.

我通过创建一个自定义集合类存储选中的项目解决了这个问题,并把该项目在此集合之前,我克隆点击复选框的标签和clicklistener成新以上复选框,商店,新的复选框,现在到集合。这解决了复选框的奇怪行为。
这可能不是问题的最佳解决方案,因此,如果你知道什么比这更好的,请分享。

I solved the problem by creating a custom collection class to store the checked items, and before putting the item in this collection, I clone the clicked checkbox's tag and clicklistener over into a new checkbox and store that new checkbox now into the collection. This solved the strange behavior of checkboxes. This may not be the best solution to the problem, so if you know anything better than this, please share.

这篇关于底部的按钮栏重叠的ListView的最后一个元素!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆