Diese GIF ziemlich zeigt, was ich rede:Bottom Blatt erscheint nicht manchmal in komplizierten Ansicht
Ich habe eine ziemlich komplizierte DrawerLayout -> CoordinatorLayout -> ViewPager -> Fragment -> RecyclerView-Situation in meiner App.
Wenn ein Benutzer lange auf eines der Elemente im RecyclerView klickt, sendet er eine Broadcast an die ParentActivity, die dann das BottomSheet anzeigt.
Normalerweise funktioniert es gut, aber ab und zu erscheint das BottomSheet nicht. Ich habe ein FrameLayout, das als Überlagerung zwischen der ParentActivity und dem ViewPager fungiert. Wenn Sie auf das Overlay klicken, wird das BottomSheet angewiesen, zu kollabieren. Sie können oben in der GIF sehen, dass in Situationen, in denen das BottomSheet nicht erscheint, es bei Kollaps immer noch animiert.
Dieses Verhalten passiert ziemlich häufig auf meinem Nexus 5 Genymotion (API 21) Emulator. Auf realen Geräten passiert es fast nie, aber manchmal.
Was ich bemerkt habe ist, dass, wenn ich das lange Klicken und halten bis das BottomSheet erscheint, es immer erscheint. Wenn ich sofort nach dem langen Klick loslasse, wird das BottomSheet möglicherweise nicht angezeigt.
Ich bin ziemlich sicher, dass dies eine Situation ist, in der der RecyclerView in irgendeiner Weise eingreift, aber ich kann nicht wirklich herausfinden, warum oder wie. Alle Debugging-Tipps wären willkommen.
Als Referenz hier ist das Layout in Frage:
<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
und content
-View.GONE
gesetzt werden, wenn die ViewPager eingeschaltet wird.
Dies ist der Empfänger, der das BottomSheet auslöst:
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);
}
};
UPDATE: Ich habe eine suboptimale Arbeit um an der richtigen Stelle. Ich habe BottomSheetBehavior-Status-Listener, der darauf wartet, dass das BottomSheet Expand ist, und es bewirkt, dass bottomSheet.requestLayout()
das Blatt mindestens erscheint. Die Erfahrung ist jedoch schlecht, weil das Blatt scheint zu flimmern, anstatt nach oben zu gleiten. Die requestLayout
Arbeit scheint auf realen Geräten kein Flimmern zu erzeugen.
Ich habe genau das gleiche Problem zu initialisieren. Ich habe ein Fragment auf einem unteren Blatt und die Benutzeroberfläche wird nicht zeichnen, egal was ich mache. Es scheint definitiv ein Bug in der BottomSheet-Implementierung zu sein. – chubbsondubs
@chubbsondubs Ja, das ist, was ich fürchte. Ich habe bemerkt, dass es nur auf bestimmten Telefonen zu passieren scheint (aus dem Kopf> = 21, aber ich bin mir nicht ganz sicher). Wenn ich etwas Zeit habe, werde ich ein Barebone-Beispielprojekt einrichten. Wenn ich es sauber überspielen kann, werde ich einen Fehlerbericht an Google/Android senden. –