亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在android中重復查看動畫變量的次數?

如何在android中重復查看動畫變量的次數?

湖上湖 2023-06-28 16:18:44
我有這個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);                }            }        }    }
查看完整描述

1 回答

?
墨色風雨

TA貢獻1853條經驗 獲得超6個贊

嘗試這個

animation.setRepeatCount(Animation.INFINITE);


查看完整回答
反對 回復 2023-06-28
  • 1 回答
  • 0 關注
  • 149 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號