第一次点击视图在 Android 中不起作用
First click on a View is not working in Android
我有一个 LinearLayout
需要在 NestedScrollView
里面的 CoordinatorLayout
里面点击,几乎每次我第一次点击它的时候它都不起作用,我必须再点一次。
可点击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">
编辑:好的,这很奇怪,如果我在尝试单击视图之前等待几秒钟,它会在第一次工作。只有在滚动到底部后才单击它才会失败。
我遇到了同样的问题。在 NestedScollView 中有一个 RelativeLayout 元素需要被点击。只要我没有滚动到最底部,就可以单击该元素。如果我要到达底部,我需要点击两次,除非我等待几秒钟。
事实证明问题出在 AppBarLayout 的默认 layout_behavior 上。我使用了下面 post 中建议的自定义方法,问题就解决了。
我有一个 LinearLayout
需要在 NestedScrollView
里面的 CoordinatorLayout
里面点击,几乎每次我第一次点击它的时候它都不起作用,我必须再点一次。
可点击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">
编辑:好的,这很奇怪,如果我在尝试单击视图之前等待几秒钟,它会在第一次工作。只有在滚动到底部后才单击它才会失败。
我遇到了同样的问题。在 NestedScollView 中有一个 RelativeLayout 元素需要被点击。只要我没有滚动到最底部,就可以单击该元素。如果我要到达底部,我需要点击两次,除非我等待几秒钟。
事实证明问题出在 AppBarLayout 的默认 layout_behavior 上。我使用了下面 post 中建议的自定义方法,问题就解决了。