android - View Flipper inside ViewPager with Bottom Navigation View -
i got bottom navigation in mainactivity view pager
bottomnavigationview = (bottomnavigationview) findviewbyid(r.id.bottom_navigation); final viewpager viewpager = (viewpager) findviewbyid(r.id.main_activity_view_pager); pageradapter = new fragmentpageradapter(getsupportfragmentmanager()) { @override public int getcount() { return 4; } @override public fragment getitem(int position) { switch (position) { case 0: return new fragment1(); case 1: return new fragment2(); case 2: return new fragment3(); case 3: return new fragment4(); } return null; } }; viewpager.setadapter(pageradapter); viewpager.addonpagechangelistener(new viewpager.onpagechangelistener() { @override public void onpagescrolled(int position, float positionoffset, int positionoffsetpixels) { } @override public void onpageselected(int position) { bottomnavigationview.getmenu().getitem(position).setchecked(true); } @override public void onpagescrollstatechanged(int state) { } }); bottomnavigationview.setonnavigationitemselectedlistener( new bottomnavigationview.onnavigationitemselectedlistener() { @override public boolean onnavigationitemselected(menuitem item) { switch (item.getitemid()) { case r.id.action_1: viewpager.setcurrentitem(0); break; case r.id.action_2: viewpager.setcurrentitem(1); break; case r.id.action_3: viewpager.setcurrentitem(2); break; case r.id.action_4: viewpager.setcurrentitem(3); break; default: break; } return true; } });
this works great, inside fragment 3 got viewflipper
<viewflipper android:id="@+id/flipper_date" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margintop="10dp"> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> xml code </linearlayout> </viewflipper>
this code of viewflipper :
viewflipper.setontouchlistener( new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent touchevent) { switch (touchevent.getaction()) { case motionevent.action_down: initialx = touchevent.getx(); return true; case motionevent.action_up: float finalx = touchevent.getx(); if (initialx > finalx * 1.5) { // right swipe } else if (initialx * 1.5 < finalx) { // left swipe } break; } return false; } });
i got trouble when swipe, viewpager take lead , send me lastfragment, touch event action_up of viewflipper not executed. way detect swipe viewpager put 1 finger on screen , swipe layout finger.
i don't know how handle this, possible block viewpager swipe when finger inside area of viewflipper ?
Comments
Post a Comment