2017-06-17 31 views
0

有可能使不斷變化的圖像,直到它設置最終的形象。我想改變圖像時,它的翻轉動畫android

我想改變它的翻轉圖像。 因此而翻轉

private ImageView image; 
private void images() { 

    int[] ps={R.drawable.img1,R.drawable.img2}; 
    Random r = new Random(); 
    int n=r.nextInt(2); 
    image.setImageResource(ps[n]); 

    ObjectAnimator animation = ObjectAnimator.ofFloat(coin, "rotationY", 0f, 360f); 
    animation.setDuration(500); 
    animation.setInterpolator(new AccelerateDecelerateInterpolator()); 
    animation.start(); 
} 

回答

0

是你可以爲做到這一點你應該使用翻轉動畫看起來光滑,你可以找到從Here 此代碼res/animator創建XML文件,上面的鏈接幫助

比在java文件

ObjectAnimator anim = (ObjectAnimator) 
AnimatorInflater.loadAnimator(mContext, R.animator.[FILE NAME]); 

int[] ps={R.drawable.img1,R.drawable.img2}; 
Random r = new Random(); 
int n=r.nextInt(2); 
image.setImageResource(ps[n]); 

anim.setTarget(image); 
anim.setDuration(500); 
anim.start();