I need to show images in horizontal RecyclerView
, and this RecyclerView
is inside a row of RecyclerView
. Now sometimes I receive 2 or 3 images and sometimes more that can fit in its width. So, i want it to be Scrollable when there are more items then its width and when it lists few items then i want empty area to be clickable as well. How can i achieve this behavior?
The problem i am having is concerned in first row where the area need to be clickable is not in my control.
Asked
Active
Viewed 796 times
1

Ghulam Moinul Quadir
- 1,638
- 1
- 12
- 17

Safeer
- 1,407
- 1
- 25
- 29
-
what about `recyclerView.setOnClickListener`? – Nabin Bhandari Oct 27 '17 at 12:30
-
Use `setOnClickListener` on the ImageView within the ViewModel for your horizontal RecyclerViewAdapter. – Mark O'Sullivan Oct 27 '17 at 12:49
-
using click listener on item works, but that don't gets triggered on empty space as that is not an item. – Safeer Oct 27 '17 at 12:54
-
You have to add touch listener intend of onClick listener in recycleview – ashish Oct 27 '17 at 12:58
-
can't you have a `view` with `#00000000` as it's background? – sasha199568 Oct 27 '17 at 13:08
-
@ashish i need to catch exact click behavior, not sure how can i get this with TouchListener by allowing user to scroll horizontally as well. – Safeer Oct 27 '17 at 13:18
2 Answers
0
I know, This is old question. But I was stumbled upon a similar scenario.
Place the recycler view inside card view (card view is actually a frame layout) and set the recycler view width to wrap_content instead of match_parent. and the card view (parent of the recycler) width to match_parent. This will give you the expected result.
The card view is required, if you want to have the elevated cards for wrapping the recycler view. Otherwise any ViewGroup (like LinearLayout,Framelayout) should work.

Raj kannan Iyyappan
- 807
- 9
- 10
0
You'll need to add a custom GridlayoutManager. Check this https://gist.github.com/ArthurSav/5f80e19d9ba6d562fbd5

qinmiao
- 5,559
- 5
- 36
- 39