I am trying to build a view which will allow the user to scroll an Excel-like structure both horizontally and vertically. My initial idea was to put a RecyclerView (with LinearManager) into a HorizontalScrollView. But it does not seem to work.
Here is my code:
<RelativeLayout
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.v7.widget.Toolbar
android:id="@+id/gameplay_Toolbar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="@color/accent"
app:title="@string/gameplay_score_toolbar"
app:titleMarginStart="48dp"
app:titleTextAppearance="@style/toolbar_title" />
<HorizontalScrollView
android:id="@+id/gameplay_hotizontalScroll_ScrollView"
android:layout_below="@+id/gameplay_Toolbar"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:fillViewport="true"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/gameplay_gameContents_RecyclerView"
android:layout_width="fill_parent"
android:layout_height="match_parent"/>
</HorizontalScrollView>
</RelativeLayout>
Right now it only allows the Recycler to scroll, the HorizontalScrollView seems to act like a normal FrameLayout (as the views inside the Recycler are clipping to the edge).
I think it may be relevant that the views I put into the Recycler have fixed size.
Any tips on how to get this concept to work?
[SOLVED]
All the trick is to manually set RecyclerView width, because it refuses to accept WRAP_CONTENT and always is maximally as wide as screen width. Trick is following:
and then simply:
and it WORKS! Happy coding...
sample working code: https://dl.dropboxusercontent.com/u/79978438/RecyclerView_ScrollView.zip