2016-05-13 89 views
4

有时会出现这种GIF几乎显示了我说的:下片不复杂视图

The Bug in Action

我有一个相当复杂的DrawerLayout - > CoordinatorLayout - > ViewPager - >片段 - > RecyclerView的情况正在我的应用程序中进行。

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

通常它工作正常,但每隔一段时间BottomSheet不会出现。我有一个FrameLayout,充当ParentActivity和ViewPager之间的叠加层。当你点击Overlay时,它会告知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> 

primaryViewcontent设置为View.GONE当ViewPager被打开。

这是触发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状态侦听器,等待底部表展开,它确实会导致工作表至少出现。虽然经验很差,但由于表单看起来'闪烁',而不是向上滑动。 requestLayout解决方法似乎不会在真实设备上产生闪烁。

+0

我有相同的问题之后。我在底部工作表上有一个片段,不管我做什么,UI都不会绘制。这看起来像是BottomSheet实现中的一个bug。 – chubbsondubs

+1

@chubbsondubs是的,这是我害怕的。我注意到它似乎只是在某些手机上发生的(我的头顶> = 21,但我不完全确定)。如果我有一段时间,我将设置一个准系统示例项目。如果我可以干净地复制它,我会向Google/Android提交错误报告。 –

回答

0

这是公知的问题通过谷歌开发商dicussed在某些预棒棒糖设备底部片不起作用

我发现了一天之后的R & d的溶液。试试这个

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

将这个代码初始化意见