- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经为此工作了一天,但仍然无法弄清楚。我正在为 Android Wear 设备制作 Android 应用程序,但我不知道如何检测设备上的转轮以获取滚动事件。我知道默认情况下,转轮会分配给 ScrollViews 和 Listviews 等,并且我已经让它可以工作,但我无法让它在简单的 NumberPicker 上工作。按照 Google API 的建议,我使用了 OnGenericMotionListener,虽然它没有抛出任何错误,但它仍然没有接收到任何内容。
我希望 NumberPicker 随滚轮滚动。我的代码如下。 logcat 中没有任何内容显示任何错误:
MyActivity.this.setContentView(R.layout.number_picker);
NumberPicker numberPicker = (NumberPicker) findViewById(R.id.numberPicker1);
numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
numberPicker.setMaxValue(100);
numberPicker.setMinValue(0);
numberPicker.setWrapSelectorWheel(true);
numberPicker.setOnValueChangedListener( new NumberPicker.
OnValueChangeListener() {
public void onValueChange(NumberPicker picker, int
oldVal, int newVal) {
}
});
numberPicker.setOnGenericMotionListener(new OnGenericMotionListener() {
@Override
public boolean onGenericMotion(View v, MotionEvent event) {
Log.i(TAG, "Received scroll event:" + event.getAction());
switch (event.getAction()) {
case MotionEvent.ACTION_SCROLL:
}
return false;
}
});
最佳答案
我认为您正在寻找这个:
Add custom rotary input scrolling :
If your scrollable view doesn't natively support rotary input scrolling, or if you want to do something other than scrolling in response to rotary input events (zoom in/out, turn dials, etc.), you can use the RotaryEncoder methods in the Wearable Support Library.
The following code snippet shows how to use RotaryEncoder to add custom scrolling in your app's view:
myView.setOnGenericMotionListener(new View.OnGenericMotionListener() {
@Override
public boolean onGenericMotion(View v, MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_SCROLL && RotaryEncoder.isFromRotaryEncoder(ev)) {
// Don't forget the negation here
float delta = -RotaryEncoder.getRotaryAxisValue(ev) * RotaryEncoder.getScaledScrollFactor(
getContext());
// Swap these axes if you want to do horizontal scrolling instead
scrollBy(0, Math.round(delta));
return true;
}
return false;
}
});
无论如何,你可以查看有关 android 中旋转事件的完整指南 磨损。
关于android - 如何将旋转滚动监听器附加到 Android Wear numberPicker?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50382672/
我是一名优秀的程序员,十分优秀!