我有一个
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">
编辑:好奇怪,如果我在尝试点击视图之前等待几秒钟,它第一次就可以工作。只有在滚动到底部后立即单击它才会失败。
onclick
方法。如果想将focusable
设置为true
并仍然获取第一次点击,则查看文档中的setOnFocusChangeListener
。 - Yupifalse
的那一行,但问题仍然存在。我不认为问题出在那个方法上。 :/ - Grenderfocusable
设置为true
,因为 Android Studio 建议在clickable=true
的情况下这样做。即使我删除了focusable=true
,问题仍然存在。 - Grender