【问题标题】:Android wearable:2.0.5 Breaks Drawer LayoutAndroid可穿戴设备:2.0.5 Breaks Drawer Layout
【发布时间】:2017-09-19 13:10:03
【问题描述】:

我的 Android 应用中有一个可穿戴的抽屉布局。行为是 peek 视图将显示 peek 片段,当用户向上滑动时,peek 片段将淡入内容片段。

我最近尝试将我的 android wear 项目从可穿戴设备 2.0.3 更新到可穿戴设备 2.0.5。很多组件需要从wearable.view改为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>

【问题讨论】:

    标签: android android-layout android-studio android-fragments wear-os


    【解决方案1】:

    从未找到我真正喜欢的解决方案,但这是一个可行的解决方案。

    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,它将为两个视图设置动画以使它们可见或不可见。我可以得到大致相同的效果。

    如果有内置的方法可以做到这一点,仍然感兴趣,但现在就可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-05
      相关资源
      最近更新 更多