1

I have a layout with 5 items in a LinearLayout in a ScrollView. I want the items to be clickable and not interfere with scrolling.

The problem is scrolling. If drag up/down on an item, it doesn't scroll. If I drag up/down on the margins between the items, it does scroll.

How can I handle click events for items AND allow scrolling when the user drags up/down on an item?

Note: this isn't about efficient layouts or just using a RecyclerView (which seems like overkill). I want to know how to scroll and handle children being clicked.

I've tried various combinations of click and touch listeners, GestureDetector, onInterceptTouchEvent... but I only seem to be able to either click or scroll, not both.

I followed these tutorials/answers and none have worked:

There must be something simple I'm missing... some flag or something?

Layout:

<androidx.coordinatorlayout.widget.CoordinatorLayout 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:id="@+id/rootLayout"> <ScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:id="@+id/itemOne" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:margin="16dp" /> <LinearLayout android:id="@+id/itemTwo" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:margin="16dp" /> ... 

Activity

override fun onCreate(savedInstanceState: Bundle?) { itemOne.setOnClickListener(this) itemTwo.setOnClickListener(this) ... } override fun onClick(view: View?) { when (view?.id) { R.id.itemOne-> ... R.id.itemTwo -> ... ... } } 

1 Answer 1

-1

just remove scrollView id in XML to make it unlisted in R file this will make it unclick-able in Listeners

Sign up to request clarification or add additional context in comments.

1 Comment

This did not solve the problem. The problem isn't the scrollview being clickable, it's that the clickable items consume the scroll touch events.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.