CoordinatorLayout(AppbarLayout)不能正确绘制工具栏

18

我正在使用新的设计支持库来实现滚动隐藏工具栏。但是,如果我使用Picasso加载图片,一切都很正常。如果我加载图片,有时当我向下滚动以再次显示工具栏时,我的工具栏会变成一个空白的白色矩形。请注意,在这种情况下,我仍然可以按导航切换按钮打开抽屉,尽管它没有在屏幕上显示:

https://www.dropbox.com/s/nte3pr091nt2wfx/device-2015-05-30-093222.png?dl=0

但有时它也能正常工作:

https://www.dropbox.com/s/i3u87df4x48fhj6/device-2015-05-30-094217.png?dl=0

我对此感到非常困惑,如果我禁用所有加载图像任务,则工具栏可以正确显示。以下是我的布局:

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

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

       <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways" />

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

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

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

我认为当 Picasso 加载图像到 ImageView 时,它可能会请求焦点和请求布局,而在这种情况下 CoordinatorLayout 无法正确地重新绘制工具栏,但这只是我的猜测。

任何建议都将有所帮助,非常感谢!


我也遇到了同样的问题,无法解决。任何帮助都将不胜感激... - Sayem
似乎只发生在5.1以下。 - CzBiX
1个回答

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

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

       <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways" />

       <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"/>

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

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

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

试试这个。我通过这个代码片段解决了相同的问题。在工具栏后面添加高度为1dp的虚拟视图。


你能解释一下这个问题是什么吗? - CzBiX
这是一个错误。请参见此链接 - neosarchizo
谷歌怎么回事?这个漏洞一年后还存在。 - 0101100101

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接