facebookarchive / shimmer-android

An easy, flexible way to add a shimmering effect to any view in an Android app.
http://facebook.github.io/shimmer-android/
Other
5.32k stars 695 forks source link

ShimmerDrawable not working with View.LAYER_TYPE_HARDWARE #132

Open fsgjlp opened 2 years ago

fsgjlp commented 2 years ago

ShimmerDrawable not working with View.LAYER_TYPE_HARDWARE and View.LAYER_TYPE_SOFTWARE.

Environment: Android emulator, Pixel 4 api 31

    Shimmer shimmer = new Shimmer.ColorHighlightBuilder()
        .setBaseAlpha(0.7f)
        .setHighlightAlpha(0.9f)
        .setDuration(10000)
        .setDirection(Shimmer.Direction.TOP_TO_BOTTOM)
        .setAutoStart(true)
        .build();

    ShimmerDrawable shimmerDrawable = new ShimmerDrawable();
    shimmerDrawable.setShimmer(shimmer);

    ShimmerDrawable shimmerDrawable2 = new ShimmerDrawable();
    shimmerDrawable2.setShimmer(shimmer);

    ShimmerDrawable shimmerDrawable3 = new ShimmerDrawable();
    shimmerDrawable3.setShimmer(shimmer);

    appCompatImageView.setLayerType(View.LAYER_TYPE_NONE, null);
    appCompatImageView.setImageDrawable(shimmerDrawable);

    appCompatImageView2.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    appCompatImageView2.setImageDrawable(shimmerDrawable2);

    appCompatImageView3.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    appCompatImageView3.setImageDrawable(shimmerDrawable3);
<LinearLayout 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"
  android:orientation="vertical">

  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="LAYER_TYPE_NONE" />

  <androidx.appcompat.widget.AppCompatImageView
    android:id="@+id/appCompatImageView"
    android:layout_width="100dp"
    android:layout_height="100dp" />

  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="LAYER_TYPE_HARDWARE" />

  <androidx.appcompat.widget.AppCompatImageView
    android:id="@+id/appCompatImageView2"
    android:layout_width="100dp"
    android:layout_height="100dp" />

  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="LAYER_TYPE_SOFTWARE" />

  <androidx.appcompat.widget.AppCompatImageView
    android:id="@+id/appCompatImageView3"
    android:layout_width="100dp"
    android:layout_height="100dp" />

</LinearLayout>

Screenshot

fsgjlp commented 2 years ago

@xiphirx, I would appreciate it if you could tell me why the problem is occurring.