2016-12-05 65 views
-1

我想拍攝一張帶有蝴蝶PNG併爲其製作動畫的Imageview,使其看起來像蝴蝶正在移動它的翅膀。Imageview上的蝴蝶動畫Android

如何使用Android本機動畫獲得此效果?

enter image description here

+2

你累了什麼嗎? – Gattsu

+0

我試圖創建一個kindda翻轉動畫,但它不好,也許試圖尋找一個可以提供幫助的Lib。 –

+1

我wuold使用gif。你不能使用gif嗎? – MikeKeepsOnShine

回答

0

我已經做了,在iOS上,所以你需要擴展它,並具有定時規模下來。

0

使用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; 
} 

輸出:

enter image description here

GitHub Link

Wiki Link

+1

非常感謝您的幫助,遺憾的是我無法使用gif。 –

1

它的工作,這是我做的,首先我用滑翔加載我的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)+ 100升); - >隨機時間。 randscale = random.nextFloat()* 0.5f)+ 0.3f);>>隨機量表。

謝謝大家的幫助。