I'm trying to make nested recyclerview with CardView like Play Store app home page, so far it works but not as smoothly than Play Store.
When recycler view scroll position is 0 and i start dragging right, edge effect appears as expected but soon i continue dragging up it looks like my horizontal recyclerview loses focus and parent vertical one takes over. From Play Store app you won't lose focus when continuing dragging up after a horizontal drag from edges. I insist that it only happends when i'm on recycler view edges.
In addition to this (and this is maybe related), it looks easier to initiate a horizontal scroll from Play Store app, i mean if you drag with an 30° angle from horizontal with PlayStore app horizontal scroll is initiated, but from my app it seems i need a max 10° angle to initiate mine otherwise vertical scroll take over.
Here's mine vertical recycler view code (inside a coordinator layout):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/AppStyle.Fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="?attr/colorPrimary"
android:gravity="center"
android:text="weather / places"
android:textColor="@android:color/white"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
-
mList.setLayoutManager( new LinearLayoutManager( getContext( ),
LinearLayoutManager.VERTICAL,
false ) );
mList.setAdapter( new HomeAdapter( ) );
Here is nested horizontal one:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/screen_padding">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:textSize="18sp"
tools:text="hello world"/>
<Space
android:layout_width="match_parent"
android:layout_height="10dp"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:background="@color/divider"/>
<Space
android:layout_width="match_parent"
android:layout_height="20dp"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fadingEdgeLength="30dp"
android:requiresFadingEdge="horizontal"/>
ListViewHolder( View itemView )
{
super( itemView );
list.setLayoutManager( new LinearLayoutManager( getContext( ),
LinearLayoutManager.HORIZONTAL,
false ) );
list.setHasFixedSize( true );
SnapHelper snapHelper = new LinearSnapHelper( );
snapHelper.attachToRecyclerView( list );
list.setAdapter( new ListAdapter( ) );
list.setNestedScrollingEnabled( false );
}
Just found solution, from nested horizontal recyclerview add :
childHorizontalList.addOnScrollListener( new RecyclerView.OnScrollListener( )
{
@Override
public void onScrollStateChanged( RecyclerView recyclerView, int newState )
{
super.onScrollStateChanged( recyclerView, newState );
parentVerticalList.setLayoutFrozen( newState != RecyclerView.SCROLL_STATE_IDLE );
}
} );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With