1. 程式人生 > >ConstraintSet 約束佈局獨有的 關鍵幀動畫

ConstraintSet 約束佈局獨有的 關鍵幀動畫

關鍵幀動畫:任何動畫要表現運動或變化,至少前後要給出兩個不同的關鍵狀態,而中間狀態的變化和銜接電腦可以自動完成,在Flash中,表示關鍵狀態的幀動畫叫做關鍵幀動畫Constraint 可以配合 ConstraintLayout 實現關鍵幀動畫,只需要給出     “動畫前的xml”、“動畫後的xml”、“插值器”就可以開始動畫。
val constraintSet1 = ConstraintSet()
constraintSet1.clone(rootView2)//拷貝一份 rootView2 作為動畫結束模板rootVie2: 動畫結束時的 xml 檔案
//constraintSet1.clone(baseContext,R.layout.activity_main2)//
也可以這麼clone TransitionManager.beginDelayedTransition(rootView)//設定動畫插值器 constraintSet1.applyTo(rootView)//應用到 此View = view 執行動畫;rootView: Activity 的根 View
注意:這並不是假的,類似屬性動畫那樣,rootView的控制元件位置真正的改變了。如果要反向執行動畫,不能直接用 constraintSet.clone(rootView),因為rootView的佈局已經改變了,執行起來是不會有任何變化的(親測)。必須在佈局改變之前 clone(rootView) 來拷貝開始位置的模板。還不知道如何監聽動畫結束