0

I'm developping a Android app, and I got a vertical NestedScrollView, who take all my screen, and inside multiple hoizontal RecyclerView. It's work, but the horizontal scroll is really hard to achieve.

I mean, when I scroll horizontally the gesture is catch by the NestedScrollView, and the view move up/down. I need to focus and do a real horizontal movement to scroll the RecyclerView, it's killing UX...

Here my NestedScrollView :

<android.support.v4.widget.NestedScrollView
    android:id="@+id/scrollView"
    android:scrollbars="none"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="5dp"
    android:layout_marginEnd="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginLeft="5dp"
    android:layout_marginStart="5dp">

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:id="@+id/scrollLayout"
        android:orientation="vertical" />

</android.support.v4.widget.NestedScrollView>

I'm inflating RecyclerView programmatically, because the number is define in network data, here the inflated layout :

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:textSize="@dimen/secondary_text_size"
        android:textAllCaps="true"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="@dimen/recycler_view_size" />

</LinearLayout>

And how I set my RecyclerView in Java :

LayoutInflater inflater = LayoutInflater.from(context);
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.recycler_view_layout, null, false);

RecyclerView recyclerView = (RecyclerView) layout.findViewById(R.id.recyclerView);
LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);

recyclerView.setHasFixedSize(false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(this);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setNestedScrollingEnabled(false);

I tried to change the "velocity" NestedScrollView, but I can't find good advice/post, maybe I don't find the good one. Someone can help ?

gouy_e
  • 188
  • 2
  • 7

1 Answers1

0

Hope you find it useful, as I think you need to implement one of these libraries (on GitHub you would find more):


If you want to do it with standard Android libraries, RecyclerView might be useful if you want to scroll horizontally

To prove that it has horizontally scrolling support, take a look at:

public boolean canScrollHorizontally ()

Query if horizontal scrolling is currently supported. The default implementation returns false.

Returns True if this LayoutManager can scroll the current contents horizontally

or

public int computeHorizontalScrollExtent (RecyclerView.State state)

Override this method if you want to support scroll bars.

Read computeHorizontalScrollExtent() for details.

Default implementation returns 0.

From: https://developer.android.com/reference/android/support/v7/widget/RecyclerView.LayoutManager.html

Check also subclass of RecyclerView called HorizontalGridView

Hope it help.

piotrek1543
  • 19,130
  • 7
  • 81
  • 94