【发布时间】:2017-04-01 11:35:17
【问题描述】:
我正在为 Android Wear 编写应用程序,我需要在关闭应用程序时在 Android Wear 上实现类似于 Google 地图应用程序的行为。
通常,“Swipe-To-Dismiss”手势(从左向右滑动)会关闭应用程序(活动),但您能想象一下您有图片或地图需要在应用程序中平移的情况吗?从左到右的平移始终关闭应用程序。
应该有谷歌在https://developer.android.com/training/wearables/ui/exit.html#swipe-to-dismiss上描述的解决方案。
如果您希望用户向下返回堆栈,您可以将视图包装在一个 SwipeDismissFrameLayout 对象中,该对象支持边缘滑动。边缘 当视图或其子视图从 canScrollHorizontally() 调用。边缘滑动使用户可以关闭 通过从屏幕的最左侧滑动来查看视图(当前 设置为屏幕宽度的 10%),而不仅仅是视图中的任何位置。
这是在适用于 Android 穿戴设备的 Google 地图应用中实现的。应用程序关闭,以防您开始非常靠近左边缘滑动。它被称为“边缘滑动”。
问题是 canScrollHorizontally() 必须返回 true,而我无法正确设置此视图属性 - 它始终为 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 等已弃用的类并使用电源按钮退出应用程序。
有什么想法或例子吗?
谢谢!
【问题讨论】:
-
问题的简短示例。 youtu.be/u7BkprKlReA 它应该如何工作。 youtu.be/T8gbQKr95U4
-
嗨,你解决了吗?
标签: wear-os