Imageview Android上的蝴蝶动画

Imageview Android上的蝴蝶动画,android,animation,imageview,android-animation,android-view,Android,Animation,Imageview,Android Animation,Android View,我想采取一个Imageview,有一个蝴蝶png和动画,使它看起来像蝴蝶正在移动它的翅膀 如何使用Android原生动画获得这种效果 使用简单的示例: 详细示例 // For a simple view: @Override public void onCreate(Bundle savedInstanceState) { ... ImageView imageView = (ImageView) findViewById(R.id.my_image_view); Glide.wi

我想采取一个Imageview,有一个蝴蝶png和动画,使它看起来像蝴蝶正在移动它的翅膀

如何使用Android原生动画获得这种效果

使用简单的示例: 详细示例

// For a simple view:
@Override public void onCreate(Bundle savedInstanceState) {
  ...
  ImageView imageView = (ImageView) findViewById(R.id.my_image_view);

  Glide.with(this).load("http://some image link").into(imageView);
}

// For a simple image list:
@Override public View getView(int position, View recycled, ViewGroup container) {
  final ImageView myImageView;
  if (recycled == null) {
    myImageView = (ImageView) inflater.inflate(R.layout.my_image_view, container, false);
  } else {
    myImageView = (ImageView) recycled;
  }

  String url = myUrls.get(position);

  Glide
    .with(myFragment)
    .load(url)
    .centerCrop()
    .placeholder(R.drawable.loading_spinner)
    .crossFade()
    .into(myImageView);

  return myImageView;
}
输出:


我已经在iOS中完成了,所以你需要用定时器放大和缩小它。

成功了,这就是我所做的,首先我使用Glide加载我的img,然后我创建了一个动画,如下所示:

final ScaleAnimation growanim = new ScaleAnimation(1.0f, randscale), 1.0f, 1.0f, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
        growanim.setDuration(randomDuration);
        growanim.setRepeatCount(-1);
        growanim.setRepeatMode(Animation.REVERSE);
        growanim.setInterpolator(new AccelerateInterpolator());
        img.setAnimation(growanim);
        growanim.start();
randomDuration=random.nextInt(2000-100+1)+100l);-->随机时间。 randscale=random.nextFloat()*0.5f)+0.3f);-->随机尺度


谢谢大家的帮助。

你累了吗?我试着制作了一个类似翻转的动画,但效果不好,可能是想找一个有帮助的库。我用的是gif。你不能使用gif吗?不能使用gif:/假设你想要折叠翅膀而不在屏幕上移动,我仍然认为你的选择是:(1)将图像切割成两个翅膀和一个身体;只需翻转一只翅膀即可节省空间;因此,您将有3个图像视图,并执行某种类型的翻转动画或(2)手动创建一组翅膀拍动的图像,并显示类似于GIF的图像。非常感谢您的帮助,不幸的是,我无法使用GIF。
final ScaleAnimation growanim = new ScaleAnimation(1.0f, randscale), 1.0f, 1.0f, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
        growanim.setDuration(randomDuration);
        growanim.setRepeatCount(-1);
        growanim.setRepeatMode(Animation.REVERSE);
        growanim.setInterpolator(new AccelerateInterpolator());
        img.setAnimation(growanim);
        growanim.start();