Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppBarLayout elevation change is delayed on appCompat v24.0.0

In Appcompat v24.0.0 causes rendering of shadow/elevation to AppbarLayout after Activity is visible. And a lag can easily be seen in shadow drawing to AppbarLayout.

And this lag was not there in previous Appcompat library version.

Tested using both Appcompat v24.0.0 and Appcompat v23.4.0, shadow drawing clearly seen in the new version.

like image 690
Vipul Asri Avatar asked Jun 22 '16 06:06

Vipul Asri


2 Answers

This is a bug in Appcompat v24.0.0.

References: https://code.google.com/p/android/issues/detail?id=213895

In order to minimize the delay in elevation drawing, set the duration to 1ms in your own StateListAnimator and apply it to AppbarLayout.

appbar_always_elevated.xml in animator-v21 folder under res directory.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <objectAnimator android:propertyName="elevation"
                        android:valueTo="8dp"
                        android:valueType="floatType"
                        android:duration="1"/>
    </item>

</selector>

In AppbarLayout :

<android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:fitsSystemWindows="true"
        android:stateListAnimator="@animator/appbar_always_elevated"
        android:theme="@style/AppTheme.AppBarOverlay">

</android.support.design.widget.AppBarLayout>
like image 195
Vipul Asri Avatar answered Sep 22 '22 01:09

Vipul Asri


Chris Banes said here:

The StateListAnimator owns all elevation handling now. If you want to do it yourself, set a null StateListAnimator and call setElevation() as you please.

So if your AppBarLayout is not collapsible you can use this:

<android.support.design.widget.AppBarLayout
    android:stateListAnimator="@null"
    android:elevation="@dimen/design_appbar_elevation">
like image 27
Eugen Pechanec Avatar answered Sep 18 '22 01:09

Eugen Pechanec