[我想在Android中使用眨眼动画来更改图像,并且图像是使用Glide直接从服务器加载的。或执行此操作的其他任何选项?

问题描述 投票:0回答:1

这是动画闪烁时我要更改图像的位置。我无法在其中设置多个图像,这是Android开发的新手。

enter image description here

public class MainActivity extends AppCompatActivity {

    RelativeLayout suggestion;
    CircleImageView suggestionImage;
    AnimationDrawable animation;
    BitmapDrawable frame;

    String[] imageUrl = new String[]{"https://i.picsum.photos/id/663/200/200.jpg", "https://i.picsum.photos/id/1026/200/200.jpg", "https://i.picsum.photos/id/1037/200/200.jpg"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        suggestion = (RelativeLayout) findViewById(R.id.suggestionContainer);
        suggestionImage = (CircleImageView) findViewById(R.id.suggestionImage);

        final Animation moveOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move_out);
        final Animation blink = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink);
        moveOut.setFillAfter(true);

        final Handler slide = new Handler();
        slide.postDelayed(new Runnable() {
            @Override
            public void run() {

                suggestion.startAnimation(moveOut);
            }
        }, 2100);

        suggestion.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(),"touched", Toast.LENGTH_SHORT).show();
            }
        });

            Glide.with(this)
                    .asBitmap()
                    .load(imageUrl[1])
                    .into(new CustomTarget<Bitmap>() {
                        @Override
                        public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {

                            frame = new BitmapDrawable(resource);

                            animation.addFrame(frame, 1000);
                        }
                        @Override
                        public void onLoadCleared(@Nullable Drawable placeholder) {
                        }
                    });


        animation = new AnimationDrawable();

        animation.setOneShot(true);

        suggestionImage.setBackgroundDrawable(animation);
        suggestionImage.startAnimation(blink);
        animation.start();
    }

}
java android android-animation
1个回答
0
投票

检查是否有帮助。

image = (ImageView) findViewById(R.id.image);
    Animation animation = new AlphaAnimation((float) 0.5, 0); // Change alpha from fully visible to invisible
    animation.setDuration(500); // duration - half a second
    animation.setInterpolator(new LinearInterpolator()); // do not alter
                                                         // animation
                                                         // rate
    animation.setRepeatCount(Animation.INFINITE); // Repeat animation
                                                  // infinitely
    animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the
                                                // end so the button will
                                                // fade back in
    image.startAnimation(animation);
© www.soinside.com 2019 - 2024. All rights reserved.