屬性動畫的兩種實現方法

2021-08-14 21:03:45 字數 1999 閱讀 9603

方法一:根據資料processlist解析出

totaltime,使用

animatorset 來組合動畫,並把每一組動畫加入animations 進行管理。

private float 

totaltime = 0

;private listanimations = new arraylist<>();

private void

createanim(qztextview textview, listprocesslist)

if(totaltime > this.totaltime)

animatorset animatorset = new animatorset();

animatorset.playsequentially(sets);

/*animatorset.addlistener(new animatorlisteneradapter()

});*/

animations.add(animatorset);

}}

animatorset沒有迴圈的方法,所以使用handler根據totaltime進行
private handler mhandler = new handler(new handler.callback() 

mhandler.sendemptymessagedelayed(0

, (long) (totaltime * 1000));

return false;

}});

動畫建立完之後,使用

mhandler.sendemptymessage(0);來開始動畫,

onrestart和

onstop分別開始和取消動畫,已經handler的訊息。

@override

protected void

onrestart()

}@override

protected void

onstop()

}

方法二:使用keyframe,同樣也需要對每乙個動畫進行管理,如在ondestroy的方法裡進行cancel操作。
private void 

createanim2(qztextview textview, listprocesslist)

keyframe keyframes = new keyframe[processlist.size() + 1];

float cost = 0

;for (int i = 0

; i < processlist.size(); i++)

cost += process.cost / totaltime;

keyframe f = keyframe.offloat(cost, process.end);

keyframes[i+1] = f;

} for(int i = 0

; i < keyframes.length

; i++)

propertyvaluesholder px = propertyvaluesholder.ofkeyframe("scalex"

, keyframes);

propertyvaluesholder py = propertyvaluesholder.ofkeyframe("scaley"

, keyframes);

objectanimator objectanimator = objectanimator.ofpropertyvaluesholder(textview, px, py);

objectanimator.setduration((long) totaltime*1000);

objectanimator.setrepeatcount(valueanimator.infinite

);objectanimator.start();

}

objective C 中兩種實現動畫的方法

第一種方法 uiview beginanimations curl context nil 動畫開始 uiview setanimationduration 1.25 動畫持續時間 uiview setanimationcurve uiviewanimationcurveeaseinout 動畫速度...

RMQ的兩種實現方法

st表實現rmq rmq演算法 range minimum maximum query 是求區間極值的高效演算法,依據所需實現的不同效能可以有多種寫法,這裡主要講基於線段樹和稀疏表 sparse table 的兩種方法 線段樹是維護區間的一類高效資料結構,依據這個特性,我們可以用線段樹實現rmq演算...

兩種隱藏屬性

1.visiblity hidden僅僅隱藏內容,該元素所佔位置依然存在 2.display none,不僅隱藏內容,而且不佔位置 display還可以設定元素的顯示模式 inline值可以將塊級元素以內聯元素的形式顯示此時width和height屬性無效,其空間取決於元素的內容 inline bl...