2017-03-06 26 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