i have recyclerview
inside viewpager
occupies bottom half of screen, , want have entire screen scroll if recyclerview
s received vertical scroll event.
ui hierarchy in nutshell:
coordinatorlayout --- appbarlayout --- toolbar --- bunch of static linearlayouts, occupy of screen --- tablayout --- viewpager --- fragments recyclerview
what have:
to understanding, recyclerview
memory-efficient , tries fit in whatever space available in screen. in app, have viewpager
hosting multiple tabs, each of have recyclerview
display different things.
could please give me ideas of make whole screen scroll? i'm guessing best shot add collapsingtoolbarlayout
parallax static content in middle of screen. tried this, ui broken. it's difficult since want content in middle of screen scroll out, not toolbars on top. didn't have luck nestedscrollview
either, apparently compatibility viewpager
, coordinatorlayout
not straight-forward..
main activity layout:
<android.support.design.widget.coordinatorlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" > <android.support.design.widget.appbarlayout android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_behavior="@string/appbar_scrolling_view_behavior" > <android.support.v7.widget.toolbar android:id="@+id/toolbar_contributor" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" android:focusableintouchmode="true"> <android.support.v7.widget.searchview android:id="@+id/searchview_contributor" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerinparent="true" android:icon="@drawable/ic_search_white_24dp" app:defaultqueryhint="bla bla" app:iconifiedbydefault="false"/> <imagebutton android:layout_width="24dp" android:layout_height="24dp" android:background="@android:color/transparent" android:src="@drawable/ic_person_outline_black_24dp"/> </android.support.v7.widget.toolbar> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight=".5" android:text="la bla"/> <button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight=".5" android:text="bla bla"/> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical" > <!-- bunch of stuff, irrelevant --> <android.support.design.widget.tablayout android:id="@+id/tablayout_profile" android:layout_width="match_parent" android:layout_height="40dp"/> </linearlayout> <android.support.v4.view.viewpager android:id="@+id/viewpager_profile" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </android.support.design.widget.appbarlayout> </android.support.design.widget.coordinatorlayout>
the fragment inside viewpager:
<framelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.recyclerview android:id="@+id/recyclerview_photos" android:layout_width="match_parent" android:layout_height="match_parent" /> </framelayout>
thanks in advance!
update: responses received here (for thankful) came bit late. if knows correct answer, please let me know!
public class customrecyclerview extends recyclerview { public customrecyclerview(context context) { super(context); } public customrecyclerview(context context, attributeset attrs) { super(context, attrs); } public customrecyclerview(context context, attributeset attrs, int defstyle) { super(context, attrs, defstyle); } int lastevent = -1; boolean islasteventintercepted = false; private float xdistance, ydistance, lastx, lasty; @override public boolean onintercepttouchevent(motionevent e) { switch (e.getaction()) { case motionevent.action_down: xdistance = ydistance = 0f; lastx = e.getx(); lasty = e.gety(); break; case motionevent.action_move: final float curx = e.getx(); final float cury = e.gety(); xdistance += math.abs(curx - lastx); ydistance += math.abs(cury - lasty); lastx = curx; lasty = cury; if (islasteventintercepted && lastevent == motionevent.action_move) { return false; } if (xdistance > ydistance) { islasteventintercepted = true; lastevent = motionevent.action_move; return false; } } lastevent = e.getaction(); islasteventintercepted = false; return super.onintercepttouchevent(e); }
}
just change recyclerview .
Comments
Post a Comment