android - ListView in BottomSheet -
i ran problem had simple listview
in bottomsheet
, listview
had enough items fill screen , scroll more.
when scroll down, seems work when tried scroll up, scrolling bottomsheet
, closing view instead of scrolling listview
.
i able find solution after while , since couldn't find anywhere here, figured post here.
the solution extend listview
this:
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; } }
then in layout file 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>
then finally, in activity
/fragment
:
bottomsheetdialog dialog = new bottomsheetdialog(context); dialog.setcontentview(r.layout.bottom_sheet_view); bottomsheetlistview listview = (bottomsheetlistview) dialog.findviewbyid(r.id.listviewbtmsheet); // apply adapter - add data listview dialog.show();
this provide bottomsheet
working listview
scroll.
Comments
Post a Comment