【问题标题】:Butterfly animation on Imageview Android [closed]Imageview Android上的蝴蝶动画[关闭]
【发布时间】:2017-04-19 23:45:27
【问题描述】:

我想要一个带有蝴蝶 png 的 Imageview 并对其进行动画处理,使其看起来像蝴蝶在移动它的翅膀。

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

【问题讨论】:

  • 你累了吗?
  • 我尝试过制作一个有点翻转的动画,但效果不佳,也许正在寻找可以提供帮助的 Lib。
  • 我会使用 gif。不能用 gif 吗?
  • 不能使用 gif :/
  • 假设您想要折叠翅膀而不在屏幕上移动,我仍然认为您的选择是(1)将图像切割成 2 个翅膀和 1 个身体;只需翻转一个机翼即可节省空间;因此您将拥有 3 个图像视图,并执行某种类型的翻转动画或 (2) 手动创建一组带有翅膀拍动的图像并显示类似于 gif 的图像

标签: android animation imageview android-animation android-view


【解决方案1】:

它成功了,这就是我所做的,首先我使用 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);---> 随机尺度。

感谢大家的帮助。

【讨论】:

    【解决方案2】:

    我已经在 iOS 中完成了这项工作,因此您需要使用计时器对其进行放大和缩小。

    【讨论】:

      【解决方案3】:

      使用Glide 简单示例:

      ImageView iView = (ImageView) findViewById(R.id.test_image);
      if (iView != null)
      Glide.with(this).load("http://i.imgur.com/1ALnB2s.gif").asGif().into(iView);
      

      详细示例

      // 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;
      }
      

      输出:

      GitHub Link

      Wiki Link

      【讨论】:

      • 非常感谢您的帮助,很遗憾我无法使用 gif。
      猜你喜欢
      • 1970-01-01
      • 2013-12-01
      • 1970-01-01
      • 2012-10-20
      • 2015-03-15
      • 2011-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多