0

我的Android應用程序中有一個可穿戴的抽屜佈局。行爲是peek視圖會顯示peek片段,當用戶刷新時,peek片段會淡入內容片段。Android可穿戴式:2.0.5打破抽屜佈局

我最近試圖將我的穿戴項目從穿戴2.0.3更新到穿戴2.0.5。很多組件需要從可穿戴視圖更改爲wear.widget

更新後,兩個碎片顯示抽屜打開或關閉的天氣。我嘗試手動淡入淡出這些內容,但似乎沒有辦法順利或輕鬆地做到這一點。以前的行爲可能了嗎?我不得不重新安排一些東西,以使其工作。是否有不同的格式我應該使用,這將會得到我以前的行爲?謝謝!

上抽屜佈局:

<android.support.wearable.view.drawer.WearableActionDrawer 
    android:id="@+id/bottom_action_drawer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="?android:attr/colorPrimary" 
    app:drawer_content="@+id/nowPlayingFragment"> 
    <!-- Peek View --> 
    <fragment 
     android:id="@+id/peekFragment" 
     android:name="com.turndapage.navmusic.ui.fragment.PeekFragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <fragment 
     android:id="@+id/nowPlayingFragment" 
     android:name="com.turndapage.navmusic.ui.fragment.NowPlayingFragment" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

</android.support.wearable.view.drawer.WearableActionDrawer> 

新抽屜佈局:

<android.support.wear.widget.drawer.WearableActionDrawerView 
    android:id="@+id/bottom_action_drawer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="?android:attr/colorPrimary" 
    app:drawer_content="@+id/nowPlayingFragment" 
    app:peekView="@+id/peek_view"> 


    <fragment 
     android:id="@+id/nowPlayingFragment" 
     android:name="com.turndapage.navmusic.ui.fragment.NowPlayingFragment" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <!-- Peek View --> 
    <fragment 
     android:id="@+id/peekFragment" 
     android:name="com.turndapage.navmusic.ui.fragment.PeekFragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

</android.support.wear.widget.drawer.WearableActionDrawerView> 

回答

0

從來沒有發現一個解決方案,我真的很喜歡,但這裏是一個工程。

wearableDrawerLayout.setDrawerStateCallback(new WearableDrawerLayout.DrawerStateCallback() { 

     @Override 
     public void onDrawerStateChanged(WearableDrawerLayout layout, int newState) { 
      super.onDrawerStateChanged(layout, newState); 
      if(nowPlayingUtil != null) { 
       // If the drawer is settling into position and it was opened all the way. 
       if (wearableActionDrawer.getDrawerState() == WearableDrawerView.STATE_SETTLING && nowPlayingUtil != null) { 
        // Transitioning from peek view 
        if (drawerState == "drawerPeeking") 
         nowPlayingUtil.fadeToOpen(); 
        // Transitioning from open view 
        else if (drawerState == "drawerOpen") 
         nowPlayingUtil.fadeToPeek(); 
        else if (drawerState == "drawerClosed") 
         nowPlayingUtil.fadeToPeek(); 
       } 
       if (wearableActionDrawer.getDrawerState() == WearableDrawerView.STATE_IDLE) { 
        // update the previous State 
        if (wearableActionDrawer.isOpened()) { 
         drawerState = "drawerOpen"; 
         nowPlayingUtil.fadeToOpen(); 
        } else if (wearableActionDrawer.isPeeking()) { 
         drawerState = "drawerPeeking"; 
         nowPlayingUtil.fadeToPeek(); 
        } else if (wearableActionDrawer.isClosed()) { 
         drawerState = "drawerClosed"; 
         nowPlayingUtil.fadeToPeek(); 
        } 
       } 
      } 
     } 
    }); 

所以在我的例子,我有兩個功能,一個是fadeToOpen,一個用於fadeToPeek將動畫的兩種觀點,使它們可見或不可見。我可以得到同樣的效果。

如果有內置的方法可以做到這一點,仍然很感興趣,但現在這樣做。