Android支持库问题23.2.1 AppBarLayout setExpanded

Dal*_*kar 6 java android android-support-library android-support-design

我已将Android支持库升级23.1.1到,23.2.1并且AppBarLayout setExpanded方法不再像过去那样工作.

我有CollapsingToolbarLayout占据整个屏幕,在它下面有NestedScrollView持有其他视图.向上和向下滑动会完全折叠/展开工具栏布局,从而显示或隐藏带内容的滚动视图.

手动滑动工作正常,但我也有按钮触发AppBarLayout setExpanded方法与true/false参数自动折叠/扩展工具栏.使用版本,23.1.1此方法也可正常工作,但23.2.1只有第一次折叠工具栏将在下方滚动视图中显示内容,所有后续折叠都不会.setExpanded(true)折叠工具栏时的触发方法将显示我的滚动视图的内容,并且扩展动画将按照预期的方式工作.

可以在API为22或更低的设备/仿真器上重现问题.

我有什么想法可以在23.2.1库中修复这种行为?


展示上述行为的基本示例:

MainActivity.java

package com.test.displaym;

import android.support.design.widget.AppBarLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void btnClick(View v)
    {
        View iv = findViewById(R.id.image_view);
        AppBarLayout bar = (AppBarLayout) findViewById(R.id.app_bar);

        if (iv.getTop() == 0) bar.setExpanded(false);
        else bar.setExpanded(true);
    }
}
Run Code Online (Sandbox Code Playgroud)

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="com.test.displaym.MainActivity">

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

        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            >

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/toolbar_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="@color/colorPrimary"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/image_view"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerCrop"
                    app:layout_collapseMode="parallax"/>

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

        <android.support.v4.widget.NestedScrollView
            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:id="@+id/page_scroll"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <TextView android:id="@+id/page"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text = "Some text\n12345\n"
                      android:orientation="vertical">
            </TextView>
        </android.support.v4.widget.NestedScrollView>

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

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Scroll"
        android:id="@+id/button"
        android:onClick="btnClick"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"/>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

的build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.test.displaym"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support:design:23.2.1'
    compile 'com.android.support:support-v4:23.2.1'
}
Run Code Online (Sandbox Code Playgroud)

其余项目文件与具有空活动的基本Android Studio项目相同.

  • 正确行为的屏幕快照 - 在使用SCROLL按钮触发折叠/展开动画期间,文本应始终可见.仅当工具栏(蓝色区域)完全覆盖屏幕时,它才不可见.

在此输入图像描述

  • 断开行为的屏幕快照 - 在按钮触发的工具栏折叠动画期间,文本不可见SCROLL.

在此输入图像描述

屏幕快照上方的红色箭头表示应观察的屏幕区域.

dar*_*xan -1

关于适合SystemWindows 的事情发生了变化。

从 AppBarLayout 和 CollapsingToolbarLayout 中删除此属性。

仅保留在 CoordinatorLayout 中。