wear-os - 边缘滑动和应用程序退出 Android Wear 2.0

标签 wear-os

我正在为 Android Wear 编写应用程序,我需要在关闭应用程序时实现与 Android Wear 上的 Google map 应用程序类似的行为。

通常,“Swipe-To-Dismiss”手势(从左向右滑动)关闭应用程序(事件),但您能想象您有图片或 map 并且需要在应用程序中平移的情况。从左到右的平移始终关闭应用程序。

谷歌在 https://developer.android.com/training/wearables/ui/exit.html#swipe-to-dismiss 上应该有一个解决方案.

If you want the user to go down the back stack, you can wrap the view in a SwipeDismissFrameLayout object, which supports edge swipe. Edge swipe is enabled when the view or its children returns true from a canScrollHorizontally() call. Edge swipe enables the user to dismiss the view by swiping from the leftmost side of the screen (currently set to 10% of the screen width) and not just anywhere in the view.



这是在适用于 Android Wear 的 Google map 应用程序中实现的。应用程序已关闭,以防万一您开始非常靠近左边缘滑动。它被称为“边缘滑动”。

问题是 canScrollHorizo​​ntally() 必须返回 true 而我无法正确设置此 View 属性 - 它始终为 false。 https://developer.android.com/reference/android/support/wearable/view/SwipeDismissFrameLayout.html

布局文件。

<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.SwipeDismissFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/swipe_dismiss_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:isScrollContainer="true"
    android:nestedScrollingEnabled="true"
    tools:context="jhettler.wearmaps.MainActivity"
    tools:deviceIds="wear">

    <RelativeLayout
        android:id="@+id/map_area"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fadeScrollbars="false"
        android:isScrollContainer="true"
        android:nestedScrollingEnabled="true">

    </RelativeLayout>

</android.support.wearable.view.SwipeDismissFrameLayout>


我不想实现诸如 DismissOverlayView 之类的弃用类并使用电源按钮退出应用程序。

任何想法或例子如何做到这一点?

谢谢!

最佳答案

尝试使用以下代码禁用滑动即可关闭:

<resources>
  <style name="AppTheme" parent="@android:style/Theme.DeviceDefault">
    <item name="android:windowSwipeToDismiss">false</item>
  </style>
</resources> 

Disabling swipe-to-dismiss generally is not recommended because the user expects to dismiss any screen with a swipe. In an exceptional case, you can set windowSwipeToDismiss to false and the user would press the power button to exit your app.



这可以在 Behavior Changes 中找到适用于 Android Wear 2.0 的文档。此处讨论了重新引入“滑动即可关闭”、电源按钮返回表盘以及 Android Wear 2.0 的其他更改等内容。

希望这可以帮助。

关于wear-os - 边缘滑动和应用程序退出 Android Wear 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43156319/

相关文章:

Android Wear 图片滚动条

android - 通过蓝牙将数据从 Android Wear watch 传输到手机

android - 通知未出现在 watch 上

Android手持设备和可穿戴设备收不到消息

android - 以编程方式检测应用是否适用于 Android Wear

Android Wear - 在没有 WearableListenerService 的情况下接收来自 Wear 的消息?

java - Android:如何添加API异常?

java - Android wear开发相关疑惑 |初学者

android - Android 手机上可用的所有布局元素是否都适用于 Android Wear?

android - 启用互联网连接 - Android Wear