繁体   English   中英

有时在复杂视图中不会出现底部工作表

[英]Bottom Sheet doesn't appear sometimes in complicated view

这个GIF几乎显示了我在说什么:

行动中的错误

我的应用程序中有一个相当复杂的DrawerLayout - > CoordinatorLayout - > ViewPager - > Fragment - > RecyclerView情况。

当用户长时间点击RecyclerView中的一个项目时,它会向ParentActivity发送一个广播,然后发出BottomSheet信号。

通常它工作正常,但每隔一段时间就不会出现BottomSheet。 我有一个FrameLayout,它充当ParentActivity和ViewPager之间的叠加层。 单击“叠加”时,它会告诉BottomSheet折叠。 你可以在上面的GIF中看到,在BottomSheet没有出现的情况下,它仍然会在崩溃时动画。

在我的Nexus 5 Genymotion(API 21)模拟器上经常发生这种情况。 在真实的设备上它几乎从未发生过,但有时也会发生。

我注意到的是,如果我长按并按住直到BottomSheet出现,它总是出现。 当我在注册长按后立即释放可能不会出现BottomSheet时。

我很确定这是RecyclerView在某种程度上干扰的情况,但我无法弄清楚为什么或如何。 任何调试技巧将不胜感激。

这里参考的是有问题的布局:

<android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout"
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/gray"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginEnd="64dp"
                app:expandedTitleMarginStart="48dp"
                app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <android.support.v7.widget.Toolbar
                        android:id="@+id/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        android:background="@color/green"
                        android:elevation="4dp"
                        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
                        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

                    <android.support.design.widget.TabLayout
                        android:id="@+id/budget_display_mode_tabs"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@color/green"
                        android:elevation="4dp"
                        android:visibility="gone"
                        app:tabGravity="fill"
                        app:tabIndicatorColor="@color/green"
                        app:tabMode="fixed" />

                </LinearLayout>

            </android.support.design.widget.CollapsingToolbarLayout>

        </android.support.design.widget.AppBarLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/view_pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:visibility="gone"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" >

            <LinearLayout
                android:id="@+id/content"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/gray"
                android:orientation="vertical" />

        </FrameLayout>

        <FrameLayout
            android:id="@+id/primary_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="?attr/actionBarSize"
            android:background="@null"
            android:orientation="vertical">

            <ProgressBar
                android:id="@+id/progress"
                style="@style/ProgressBar"/>

        </FrameLayout>

        <LinearLayout
            android:id="@+id/full_screen_overlay"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:visibility="gone"
            android:background="@color/blackLight"
            android:orientation="vertical"/>

        <LinearLayout
            android:id="@+id/bottom_sheet"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="true"
            android:background="@color/gray"
            android:orientation="vertical"
            app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

            <TextView
                android:id="@+id/bottom_edit"
                style="@style/BottomSheetButton"
                android:text="@string/option 1"/>

        </LinearLayout>

    </android.support.design.widget.CoordinatorLayout>


    <android.support.v7.widget.RecyclerView
        android:id="@+id/nav_list"
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:layout_gravity="left|start"
        android:background="@color/kEDColorGrayLightest" />

</android.support.v4.widget.DrawerLayout>

primaryView View.GONE时, primaryViewcontent设置为View.GONE

这是触发BottomSheet的接收器:

private final BroadcastReceiver modifyBudgetItemBroadcastReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(final Context context, final Intent intent) {
        bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
        fullScreenOverlay.setVisibility(View.VISIBLE);
    }
};

更新:我有一个次优的工作。 我有BottomSheetBehavior状态监听器,等待BottomSheet展开,它执行bottomSheet.requestLayout()这导致至少出现工作表。 虽然经验很差,因为工作表似乎“闪烁”而不是向上滑动。 requestLayout解决方法似乎不会在真实设备上产生闪烁。

这是谷歌开发人员所讨论的已知问题。在一些Pre-lollipop设备上,底页不起作用

研发后一天我找到了解决方案。 尝试这个

ViewCompat.postOnAnimation(yourCoordinator, new Runnable() {
            @Override
            public void run() {
                ViewCompat.postInvalidateOnAnimation(yourCoordinator);
            }
        });

在初始化视图后放置此代码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM