
我遇到了一个问题,我在BottomSheet中有一个简单的ListVIEw,ListVIEw有足够的项目来填充屏幕并滚动更多.
当我向下滚动时,一切似乎都有效,但当我尝试向上滚动时,它滚动BottomSheet本身并关闭视图而不是仅滚动ListVIEw.
过了一段时间我找到了一个解决方案,因为我在这里找不到它,我想我会在这里发布.
解决方法:
解决方案是像这样扩展ListVIEw:
public class BottomSheetListVIEw extends ListVIEw { public BottomSheetListVIEw (Context context, AttributeSet p_attrs) { super (context, p_attrs); } @OverrIDe public boolean onIntercepttouchEvent(MotionEvent ev) { return true; } @OverrIDe public boolean ontouchEvent(MotionEvent ev) { if (canScrollVertically(this)) { getParent().requestdisallowIntercepttouchEvent(true); } return super.ontouchEvent(ev); } public boolean canScrollVertically (AbsListVIEw vIEw) { boolean canScroll = false; if (vIEw !=null && vIEw.getChildCount ()> 0) { boolean isOntop = vIEw.getFirstVisibleposition() != 0 || vIEw.getChildAt(0).gettop() != 0; boolean isAllitemsVisible = isOntop && vIEw.getLastVisibleposition() == vIEw.getChildCount(); if (isOntop || isAllitemsVisible) { canScroll = true; } } return canScroll; }}然后在你的布局文件bottom_sheet_vIEw.xml中:
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> <com.mypackage.name.BottomSheetListVIEw androID:ID="@+ID/ListVIEwBtmSheet" androID:divIDer="@color/colorPrimary" androID:divIDerHeight="1dp" androID:layout_weight="1" androID:layout_wIDth="match_parent" androID:layout_height="0dp" /></linearLayout>最后,在你的Activity / Fragment中:
BottomSheetDialog dialog = new BottomSheetDialog(context);dialog.setContentVIEw(R.layout.bottom_sheet_vIEw);BottomSheetListVIEw ListVIEw = (BottomSheetListVIEw) dialog.findVIEwByID(R.ID.ListVIEwBtmSheet);// apply some adapter - add some data to ListvIEwdialog.show();这将提供一个完全使用ListVIEw滚动的BottomSheet.
总结以上是内存溢出为你收集整理的android – BottomSheet中的ListView全部内容,希望文章能够帮你解决android – BottomSheet中的ListView所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)