简体   繁体   中英

Android: OnClick margin space in RecyclerView.Adapter

I want to execute some action if user click the space(created by margin) between two items in RecyclerView, however I did not found a way to do that. OnTouchListener might do the trick but it is posible to get view by given coordinate (x, y)?

Setting onTouchListener on root does not do the trick, it seems like the event is handled by view on top of it. I want to register that can handle all ontouch event and pass the ontouch event to the right view after pre-handle.

You can also achieve this by creating margin using View tag-

Something like this-

                     <View
                        android:id="@+id/left_margin_view"
                        android:layout_width="10dp"
                        android:layout_height="match_parent"/>

Remove margin applied to recycle item root tag and create view and now you can use any event listener with this view id left_margin_view .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM