2012-12-17 119 views
0

我有一个FrameLayout并动态添加10个ImageViews到它。 然后我用一个下载的图像填充它,并想为它设置动画效果。 缩放和翻译动画从错误的位置开始。它应该从屏幕中间开始。当我在运行时在ImageView中更改drawable(使用另一个下载的图像)并再次设置动画时,动画从正确的位置开始(从屏幕中间开始)。动态ImageView动画

我想我必须以某种方式初始化位置。

这是我如何创建imageViews:

mImages = new ImageView[10]; //Fill Array with ImageViews 
    for(int i = 0; i < bufferCount; i++){ // ,Initialize them 
     mImages[i]= new ImageView(mCtx); 
     mImages[i].setVisibility(View.GONE);//,make them Invisible 
     ContentFrame.addView(mImages[i]); //and add them to the view 
    } 

,这是我的动画:

 Animation animation = AnimationUtils.loadAnimation(mCtx ,R.anim.anim1); 
     animation.setAnimationListener(mAnimationDone); 

     mImages[imgPos].setVisibility(View.VISIBLE); 
     mImages[imgPos].startAnimation(animation); 

回答

0

我的动画

<scale 
android:fromXScale="1.0" 
android:fromYScale="1.0" 
android:toXScale="2.0" 
android:toYScale="2.0" 
android:pivotX="50%" android:pivotY="50%" 
/> 


<alpha android:fromAlpha="1.0" 
    android:toAlpha="0.5" 
    /> 

</set>