底部按钮栏与Listview的最后一个元素重叠!
我有一个列表视图,它是一个活动的一部分。我希望用户可以选择批量删除列表视图中的项目,因此当他从菜单中选择相应的选项时,每个列表项目都会在其旁边有一个复选框。当用户单击任何复选框时,按钮栏将从底部向上滑动(如在gmail应用程序中)并单击删除按钮删除所选项目,但单击栏上的取消按钮将取消选中所有选中的项目。底部按钮栏与Listview的最后一个元素重叠!
这是我的网页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本身添加底部边距,或者在使按钮条可见之前将LinearLayout包装到列表视图中,但它引入了其他错误,例如单击一个复选框来检查ListView中的某个复选框。
没有测试这个,但我很确定它是造成这个:)的FrameLayout。因为FrameLayout不关心你给它的“重量”。 FrameLayout只是把你插入的视图放在彼此的前面。第二个是你给的,你说android:layout_gravity =“bottom”,它使它在底部对齐。但只是在列表视图的前面。删除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>
嘿帕特里克!感谢您的帮助。它部分工作。部分原因是,现在我不必手动设置底部边距,这样就有了帮助。但我仍然遇到了以前与调整视图边距有关的问题:即单击一个复选标记试图检查另一个复选框。 framelayout添加列表视图上方的按钮栏时,不会出现此问题。任何想法可能造成这种情况? – elto 2011-01-05 09:45:14
好问题..这是很难猜测为什么。如果你会分享一个小例子(整个项目的来源),那么也许我可以试着弄明白。 – 2011-01-06 06:47:35
好像我已经解决了的奇怪行为复选框的问题。首先,问题发生了,因为一旦listview被重新调整大小,它就会重新绘制自己,因此getView()会再次调用所有可见列表项。由于我使用的是ViewHolder,并且视图被重用,所以它似乎会导致相同的复选框被重新用于其他列表项目。因此,当我点击一个复选框时,其他复选框被点击。因为此刷新列表视图的调用仅在列表被调整大小时发生,并且只有在未标记其他复选框时在列表中标记复选框时才会调整列表大小,因此在第一个复选框被标记后,此问题不再出现。
我通过创建自定义集合类来存储选中的项目,并且在将项目放入此集合之前,我将单击的复选框的标记和clicklistener克隆到新的复选框并将该新复选框立即存储到采集。这解决了复选框的奇怪行为。 这可能不是解决问题的最佳解决方案,所以如果你知道比这更好的东西,请分享。
如果将RelativeLayout替换为与LinearLayout具有相同权重的LinearLayout,并保存ListView,会发生什么情况? – James 2011-01-05 08:46:43