标签: android-wear-3.0

如何在 Android Wear 中的 ScrollView 中添加旋转输入

我正在开发一个 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
            }
        }
Run Code Online (Sandbox Code Playgroud)

android android-wear-2.0 wear-os android-wear-3.0

5
推荐指数
1
解决办法
1090
查看次数