我有这个swapAnimation方法,基本上可以交换两个视图。我在循环内调用此方法,并swapAnimation每次传递该方法的不同视图。但问题是这种animation情况只会发生一次。我想让它重复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); } } } }
添加回答
举报
0/150
提交
取消