2017-03-06 60 views
0

我想在我的应用程序中使用WearableActionDrawer。以前我是用“com.google.android.support:wearable:2.0.0-alpha1”和我的布局是这样的:WearableActionDrawer偷看视图不隐藏

<?xml version="1.0" encoding="utf-8"?> 
<android.support.wearable.view.drawer.WearableDrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:rectLayout="@layout/rect_activity_main" 
    app:roundLayout="@layout/round_activity_main" 
    tools:context="com.example.grant.wearableclimbtracker.MainActivity" 
    tools:deviceIds="wear"> 

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id = "@+id/content_frame"> 
     <android.support.wearable.view.GridViewPager 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/pager" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </android.support.v4.widget.NestedScrollView> 

    <android.support.wearable.view.drawer.WearableNavigationDrawer 
     android:id = "@+id/top_navigation_drawer" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:background="@color/dark_grey"/> 

    <android.support.wearable.view.drawer.WearableActionDrawer 
     android:id="@+id/bottom_action_drawer" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/grey" /> 
</android.support.wearable.view.drawer.WearableDrawerLayout> 

后,我切换到“com.google.android.support:wearable: 2.0.0'的行为改变了。行动抽屉过去不被看到,直到我滑过来揭示行动菜单,但现在有一个抽屉视图,除非我打开菜单并选择一些东西,否则它不会消失。这是预期的行为吗?它占用了大量的房地产:

enter image description here

任何建议,将不胜感激。

+0

选中此[博客](https://www.linkedin.com/pulse/sneak-peek-latest-android-耐磨特性,而开发 - 阿比 - 琼斯)关于可穿戴式抽屉增强。它表示它显示了'WearableActionDrawer'的peek视图中的第一个动作。对于可穿戴抽屉中的其他定制,已将“peek_view”和“drawer_content”属性添加到“WearableDrawerView”中。导航抽屉的内容可以通过调用notifyDataSetChanged来更新。您也可以查看此[相关主题](https://www.reddit.com/r/AndroidPreviews/comments/4hcfin/how_to_disable_peekheads_up_notifications_on/)。 – abielita

+0

@abielita我看过两个链接,但似乎没有回答我的问题。从[android文档](https://developer.android.com/training/wearables/ui/ui-nav-actions.html): _默认情况下,操作抽屉会在用户到达顶部 或主要滚动内容的底部(即, 实现NestedScrollingChild的视图)._ 我认为问题可能是NestedScrollingChild中的内容匹配父级,所以也许android认为它已经达到了滚动视图的顶部/底部?有什么方法可以改变这种行为来默认隐藏窥视视图吗? – grantka

+0

你可能在你的代码中调用peekDrawer? – AfzalivE

回答

1

正如我怀疑的那样,当NestedScrollingChild高度匹配父视图时,操作抽屉会窥视。我能得到它的隐藏唯一方法是1DP增加NestedScrollingChild观点:

// get the screen width 
DisplayMetrics metrics = new DisplayMetrics(); 
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics); 

// set height of framelayout to be slightly larger than view 
mSessionLayout = rootView.findViewById(R.id.sessionLayout); 
mSessionLayout.setMinimumHeight(metrics.heightPixels+1); 
+0

谢谢你,它很脏,但它的作品。我做到了通过扩展布局,并覆盖'onMeasure'如下 ' @覆盖 \t保护无效onMeasure(INT widthMeasureSpec,INT heightMeasureSpec){ INT模式= MeasureSpec.getMode(heightMeasureSpec); int size = MeasureSpec.getSize(heightMeasureSpec); heightMeasureSpec = MeasureSpec.makeMeasureSpec(size + 1,mode); super.onMeasure(widthMeasureSpec,heightMeasureSpec); } ' – lionscribe