1

我正在开发一个 android wear 应用程序,我已经使用 rcView.requestFocus() 将旋转输入添加到 recyclerview,但它不适用于 NestedScrollview,所以我想知道如何将旋转输入侦听器添加到 NestedScrollview。

这是我到目前为止所做的

   binding.mainScroll.setOnGenericMotionListener { v, ev ->
            if (ev.action == MotionEvent.ACTION_SCROLL &&
                ev.isFromSource(InputDeviceCompat.SOURCE_ROTARY_ENCODER)
            ) {

                val delta = -ev.getAxisValue(MotionEventCompat.AXIS_SCROLL) *
                        ViewConfigurationCompat.getScaledVerticalScrollFactor(
                            ViewConfiguration.get(applicationContext), applicationContext
                        )
                
                v.scrollBy(0, delta.roundToInt())
                true
            } else {
                false
            }
        }
4

1 回答 1

0

在你activity_layout添加requestFocus里面的ScrollView. 您需要您的 API 为 28 或更高。例子:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <requestFocus
        android:focusable="true"
        android:focusableInTouchMode="true"/>
</ScrollView> 
于 2022-02-17T20:32:05.043 回答