Is there an alternative to CircleImageView with TransitionAnimation support?

I have an ImageView. After loading the bitmap into onPostExecute, I call setImageDrawable to populate the imageView (I use CircleImageView) with the image. But TransitionDrawable shows only the 1st image and the transaction is not performed. How should I do it? Thanks in advance.

private void setImageDrawable(ImageView imageView, Bitmap bitmap) {
            if (mFadeInBitmap) {
                BitmapDrawable drawable = null, placeholder = null;
                if (bitmap != null) {
                    drawable = new BitmapDrawable(mResources, bitmap);
                    placeholder = new BitmapDrawable(mResources, mPlaceHolderBitmap);
                }
                final TransitionDrawable td =
                            new TransitionDrawable(new Drawable[] {
                                placeholder,
                                drawable,
                        });

            imageView.setImageDrawable(td);
            td.startTransition(200);
        } else {
            imageView.setImageBitmap(bitmap);
        }
    }

UPDATE: I found a solution why this does not work for me in the CircleImageView documentation: "Using TransitionDrawable with CircleImageView does not work properly and leads to corrupted images." ( https://github.com/hdodenhof/CircleImageView ).

So can anyone suggest to me how I can get a circle image fading into the animation?

2: , , , , , . .

fade_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">
    <alpha
        android:fromAlpha="1.0"
        android:toAlpha="0.0"
        android:duration="100"
        android:interpolator="@android:anim/accelerate_interpolator"
        />
</set>

fade_in.xml , , Alfa Alfa. , :

 Animation anim = AnimationUtils.loadAnimation(mContext, R.anim.fade_out);
 imageView.startAnimation(anim);
 final Handler handler = new Handler();

 handler.postDelayed(new Runnable() {

     @Override
     public void run() {
         imageView.setImageBitmap(value);//changing to different image ,here you will set image that you have loaded
         Animation anim = AnimationUtils.loadAnimation(mContext, R.anim.fade_in);
         imageView.startAnimation(anim);
      }

  }, 100);

, .

+4
1

, , :

private void setImageDrawable(ImageView imageView) {
    Bitmap bitmap1 = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    Bitmap bitmap2 = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    new Canvas(bitmap1).drawRect(0, 0, 100, 100, mWhitePaint);
    new Canvas(bitmap2).drawRect(0, 0, 100, 100, mBlackPaint);

    BitmapDrawable drawable1 = new BitmapDrawable(getResources(), bitmap1);
    BitmapDrawable drawable2 = new BitmapDrawable(getResources(), bitmap2);
    TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] {drawable1, drawable2});
    imageView.setImageDrawable(transitionDrawable);
    transitionDrawable.startTransition(3000);
}

, , bitmap null, mPlaceHolderBitmap ( null). 3 , , , , 200 , .

+2

Source: https://habr.com/ru/post/1598401/


All Articles