Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First click on a View is not working in Android

I have a LinearLayout which needs to be clickable inside a NestedScrollView inside a CoordinatorLayout and almost all the time the first time I click it it simply doesn't work, I must click it another time.

Click error

Clickable LinearLayout:

<LinearLayout
            android:id="@+id/qr_code_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:clickable="true"
            android:focusable="true"
            android:background="?android:attr/selectableItemBackground"
            tools:ignore="UseCompoundDrawables">

EDIT: Okay this is very weird, if I wait some seconds before trying to click the View, it works the first time. It only fails if I click it just after scrolling to the bottom.

like image 992
Grender Avatar asked Dec 06 '25 18:12

Grender


1 Answers

I had the same problem. Inside the NestedScollView there was a RelativeLayout element needed to be clicked. As long I didn't scroll to the very bottom, the element could be clicked with a single click. If I would reach the bottom I needed two clicks, except if I waited a number of seconds.

The problem proved to be on the default layout_behavior of the AppBarLayout. I used the custom one suggested in the post below and the problem was solved.

onClick method not working properly after NestedScrollView scrolled

like image 185
strat Avatar answered Dec 08 '25 08:12

strat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!