Skip to content

Most visited

Recently visited

navigation

使用手腕手势

在您不方便触摸屏幕时,可通过手腕手势快速地与应用进行单手交互。

例如,用户可以用一只手滚动浏览通知,用另一只手端水杯。可体现手腕手势用处的示例还包括:

要查看手表上的手腕手势,请通过选择 Settings > Gestures > Wrist Gestures On 确认手势已启用。然后,在手表上完成手势教程 (Settings > Gestures > Launch Tutorial)。

应用无法使用 Android Wear 帮助中的以下手势:

可通过以下方式使用手腕手势:

每个手腕手势将被映射到 KeyEvent 类中的一个 int 常量,如下表所示:

手势 KeyEvent 说明
手腕外翻 KEYCODE_NAVIGATE_NEXT 此键代码可转到下一个项目。
手腕内翻 KEYCODE_NAVIGATE_PREVIOUS 此键代码可转到上一个项目。

使用曲线布局以支持手腕手势

WearableRecyclerView 类为列表提供一个曲线布局,并自动支持手腕手势。当视图具有焦点时,此类具有触发手腕手势的预定义操作。如需了解有关使用 WearableRecyclerView 类的信息,请参阅创建列表。另请参阅最佳做法

:在穿戴式设备支持库中, WearableRecyclerView 类取代了一个与其类似且已弃用的类。

即使您使用一个 WearableRecyclerView,您可能也希望使用 KeyEvent 类中的常量。可通过创建 WearableRecyclerView 的子类和重新实现 onKeyDown() 回调来重写预定义的操作。此行为可通过使用 setEnableGestureNavigation(false) 完全停用。另请参阅处理键盘操作

直接使用按键 Event

您可以使用 WearableRecyclerView 之外的按键 Event 触发新操作以响应手势 Event。重要的是,这些手势 Event 具有如下特点:

具体而言,这些 Event 将传递到顶部 Activity,传递到具有键盘焦点的视图。与任何其他按键 Event 一样,与实现 KeyEvent.Callback 的用户交互(如视图或 Activity)相关的类可侦听与手腕手势相关的按键 Event。Android 框架使用按键 Event 调用具有焦点的视图或 Activity;对于手势,在做出手势时调用 onKeyDown() 函数。

例如,应用可能重写视图或 Activity(都可实现 KeyEvent.Callback)中的预定义操作,如下所示:

public final class GesturesActivity extends Activity {

 @Override /* KeyEvent.Callback */
 public boolean onKeyDown(int keyCode, KeyEvent event) {
  switch (keyCode) {
   case KeyEvent.KEYCODE_NAVIGATE_NEXT:
    // Do something that advances a user View to the next item in an ordered list.
    return moveToNextItem();
   case KeyEvent.KEYCODE_NAVIGATE_PREVIOUS:
    // Do something that advances a user View to the previous item in an ordered list.
    return moveToPreviousItem();
  }
  // If you did not handle it, let it be handled by the next possible element as deemed by the Activity.
  return super.onKeyDown(keyCode, event);
 }

 /** Shows the next item in the custom list. */
 private boolean moveToNextItem() {
  boolean handled = false;
  …
  // Return true if handled successfully, otherwise return false.
  return handled;
 }

 /** Shows the previous item in the custom list. */
 private boolean moveToPreviousItem() {
  boolean handled = false;
  …
  // Return true if handled successfully, otherwise return false.
  return handled;
 }
}

最佳做法

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)