我有這個(gè)swapAnimation方法,基本上可以交換兩個(gè)視圖。我在循環(huán)內(nèi)調(diào)用此方法,并swapAnimation每次傳遞該方法的不同視圖。但問題是這種animation情況只會(huì)發(fā)生一次。我想讓它重復(fù)n次。void swapAnimation(View v1,View v2){ if(isAnimating)return; isAnimating = true; float x1,y1,x2,y2; x1 =getRelativeX(v1); x2 = getRelativeX(v2); y1 = getRelativeY(v1); y2 = getRelativeY(v2); float x_displacement = (x2-x1); float y_displacement = (y2-y1); v1.animate().xBy(x_displacement).yBy(y_displacement); v2.animate().xBy(-x_displacement).yBy(-y_displacement); v1.animate().setDuration(500); v2.animate().setDuration(500); long duration = v1.animate().getDuration(); new CountDownTimer(duration+10,duration+10){ @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { isAnimating = false; } }.start(); }public static void arrange(LinearLayout container, Context context){ MainActivity activity = (MainActivity) context; for(int i=0;i<container.getChildCount();i++){ BarView v1 = (BarView) container.getChildAt(i); for(int j=i;j<container.getChildCount();j++){ BarView v2 = (BarView) container.getChildAt(j); if(v1.getWeight() > v2.getWeight()){ Log.d(TAG, "bubbleSort: "+v1.getWeight()+">"+v2.getWeight()); activity.swapAnimation(v1,v2); } } } }
1 回答

墨色風(fēng)雨
TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超6個(gè)贊
嘗試這個(gè)
animation.setRepeatCount(Animation.INFINITE);
添加回答
舉報(bào)
0/150
提交
取消