Android animation does not repeat

后端 未结 23 1450
囚心锁ツ
囚心锁ツ 2020-11-27 14:01

I\'m trying to make simple animation that would repeat several times (or infinitely).
It seems that android:repeatCount does not work!
Here is my anim

23条回答
  •  时光取名叫无心
    2020-11-27 14:13

    I've solved this problem. This is my version of the fix:

    public class HelloAndroidActivity extends Activity {
    private static String TAG = "animTest";
    private Animation scaleAnimation;
    private int currentCover = 0;
    private List imageViews = new ArrayList(3);
    private Button btn;
    private ImageView img;
    
    /**
     * Called when the activity is first created.
     * @param savedInstanceState If the activity is being re-initialized after 
     * previously being shut down then this Bundle contains the data it most 
     * recently supplied in onSaveInstanceState(Bundle). Note: Otherwise it is null.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(TAG, "onCreate");
        setContentView(R.layout.test);
    
        img = (ImageView)findViewById(R.id.testpict);
        imageViews.add(img);
        img = (ImageView)findViewById(R.id.testpictTwo);
        imageViews.add(img);
        img = (ImageView)findViewById(R.id.testpict3);
        imageViews.add(img);
    
        scaleAnimation = AnimationUtils.loadAnimation(this, R.anim.photo_scale);
        scaleAnimation.setAnimationListener(new CyclicAnimationListener());
    
        btn = (Button)findViewById(R.id.startBtn);
        btn.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {
                imageViews.get(0).startAnimation(scaleAnimation);
            }
        });
    
    
    
    }
    
    private class CyclicAnimationListener implements AnimationListener{
    
        @Override
        public void onAnimationEnd(Animation animation) {
            currentCover += 1;
            if(currentCover >= imageViews.size()){
                currentCover = 0;
            }
            img = imageViews.get(currentCover);
            scaleAnimation = AnimationUtils.loadAnimation(HelloAndroidActivity.this, R.anim.photo_scale);
            scaleAnimation.setAnimationListener(new CyclicAnimationListener());
            img.startAnimation(scaleAnimation);
        }
    
        @Override
        public void onAnimationRepeat(Animation animation) {
            Log.d("Animation", "Repeat");
        }
    
        @Override
        public void onAnimationStart(Animation animation) {
    
        }
    
    }
    
    }
    

提交回复
热议问题