How to create a HorizantalScrollview
for this, but when I keep button in HorizantalScrollview
button width
changes to wrap_contant
I want it to be match_parent
only and when I swipe the button I need to get the RecyclerView
for RecyclerView
I can manage by keeping the LinearLayout.Horizantal
in code. All want is button to be Match_Parent
and when I swipe I need to get recyclerview

- 8,057
- 8
- 35
- 54

- 53
- 5
-
Why use `HorizantalScrollview` just use `RecyclerView` only . You can inflate different layouts depending on position . – ADM Sep 13 '18 at 05:49
-
Look at this examples https://android-pratap.blogspot.com/2015/12/horizontal-recyclerview-in-vertical.html – Gowthaman M Sep 13 '18 at 06:00
2 Answers
While the setup you've shown in the illustration should be doable, it is not considered a good practice. RecyclerView
brings efficiency to a scrollable element and putting RecyclerView
in another scrollable element (e.g. the HorizontalScrollView
in your example) can make the efficiency benefits go away and can make it less UX-friendly.
What you should do is to create a RecyclerView
that can handle multiple view types in the Adapter
. This SO answer should be enough for you to understand the concept.
And your case should look more like this:
(the illustration is for explaining purposes only, it's not entirely accurate as the RecyclerView
should not wrap its content)

- 30,698
- 10
- 94
- 132
Use HorizontalScrollView it's very simple like normal scrollview
See below example
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbarThumbHorizontal="@null" \\remove it if you don't want to use
android:scrollbarThumbVertical="@null" \\optional
android:scrollbarTrackHorizontal="@null" \\optional
android:layout_marginLeft="@dimen/margin_15dp"
android:scrollbars="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
\\define your list of item here that you want to scroll
</LinearLayout>
</HorizontalScrollView>

- 277
- 2
- 12