序文
昨夜はいつものように、食事は栄光の王のゲームを開いた後、基本的な灼熱の最初と中盤の段階では、勝つために決定の後半波に、私は断固として矢を撃つ、チームメイトと反対側を撃った直接殺す、連隊の波に勝つベースを介してプッシュ。それは素晴らしいですが、チームメイトは賞賛を発行され、私は拳をクールポイント:ありがとうございます!へへへ。
アニメーション効果
機能詳細
MotionLayout は ConstraintLayout のサブクラスで、ConstraintLayout の豊富なレイアウト機能の上に構築されています。
MotionLayoutはConstraintLayoutのサブクラスで、アニメーション機能を持ったConstraintLayoutに相当します。アニメーションコントロールとしてのMotionLayoutの利点は、Javaのコードを書く必要がなく、xmlファイルで全て完結することです。また、開始位置、終了位置、中間状態を設定するだけで、自動的にアニメーションを生成することができます。
最初に分析する集団戦は、主に3つのシナリオに分かれています:
- ホウ・イーが放った強烈なシュートは、必死の形相で歩くアーサーに命中。
- 大慈と鍾武燕は同時に草むらにしゃがみ込み、侯懿の見事な弓術を見て、草むらから出て大きな戦いに備えました。
- 大慈の2つのスキルで対面の呂凡7を気絶させ、中武燕の大技と相まって対面の2人のヒーローをKO。
シーン1
含まれるコントロール:ホウイー、アーサー、ルー・バン、ホウイーの矢
アニメーションの説明:位置についたアーサー、矢を放つホウ・イ。
まず、レイアウトファイルで、最初のMotionLayoutを追加し、すべてのコントロールを追加し、HouyiとLubanは静止状態であるため、位置制約を書き込むので、アニメーションを含む他のコントロールは、一時的に位置制約を書き込まないことができます:
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/motionLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/scene_01"
app:showPaths="false"
tools:showPaths="true">
<ImageView
android:id="@+id/houyi"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_marginLeft="180dp"
android:src="@drawable/houyi_model"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.8" />
<ImageView
android:id="@+id/houyi_arrow"
android:layout_width="66dp"
android:layout_height="66dp"
android:src="@drawable/arrow" />
<ImageView
android:id="@+id/yase"
android:layout_width="66dp"
android:layout_height="66dp"
android:src="@drawable/yase_model" />
<ImageView
android:id="@+id/luban"
android:layout_width="66dp"
android:layout_height="66dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.58"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.26"
android:src="@drawable/luban_model" />
</androidx.constraintlayout.motion.widget.MotionLayout>
app:layoutDescriptionこのプロパティは MotionLayout に対応するアニメーションシーンを表し、対応するレイアウトのすべてのモーションアニメーションの記述を含む MotionScene を参照します。- app:showPaths、このプロパティはモーションの実行時にパスを表示するかどうか、つまりすべてのアニメーションのパスを表示するかどうかを表します。
MotionLayout.DEBUG_SHOW_PATHこの属性を setDebugMode メソッドに渡すことで、コード内でアニメーションのパスを表示するかどうかを設定することもできます。
矢を放つホウイ
次に、アニメーションシーンを書くために、新しいres-xml-scene_01.xmlを作成します。
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://..com/apk/res/android"
xmlns:app="http://..com/apk/res-auto">
<Transition
app:constraintSetEnd="@+id/end"
app:constraintSetStart="@+id/start"
app:duration="2000">
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@+id/houyi_arrow"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_marginLeft="190dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.8">
</Constraint>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/houyi_arrow"
android:layout_width="66dp"
android:layout_height="66dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.65"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.35">
</Constraint>
</ConstraintSet>
</MotionScene>
ご覧のように、MotionSceneにはTransitionとConstraintSetの2つのメインタブがあります。
motion:constraintSetStartmotion:constraintSetEndトランジションは、モーションの基本的な定義を含み、andはモーションの開始状態と終了状態を表します。app:durationは、モーションを完了するのに必要な時間を表します。- 例えば、ここでは、開始制約セットと終了制約セットを表す2つのConstraintSetがあります。
ここで、Constraint属性は終点位置の要素の位置と属性を指定します:
- すべてのConstraintLayoutプロパティがサポートされています。
alpha,rotation,visibility,translationX,scaleXビューの基本的なプロパティをサポートしています。- カスタム属性もサポートされており、CustomAttributeというサブタグで表されます:
<Constraint
android:id="@+id/button" ...>
<CustomAttribute
motion:attributeName="backgroundColor"
motion:customColorValue="#D81B60"/>
</Constraint>
getBackgroundColor() setBackgroundColor()attributeName属性は、ゲッターメソッドとセッターメソッドを持つオブジェクトに一致するものです。例えば、ここではbackgroundColorが基本メソッドとビュー自体のメソッドに対応します。
さて、子孫の方に話を戻すと、ホウイの矢はホウイの位置からアーサーの位置に飛んでいるので、ホウイの矢の2つの終点の状態を設定すると、MotionLayoutが自動的に開始状態から終了状態までのアニメーションを生成して、ホウイの矢はホウイの位置からアーサーの位置に飛んでいきます。ちょっと待ってください。どうやったらアニメーションが始まるの?
Motionには、3つのアニメーショントリガーメソッドがあります:
1)onClick タグ。これは、アニメーション効果をトリガーするために、シーン内のコントロールをクリックすることを示します。このタグには2つの属性があります。
- app:targetId、アニメーションをトリガーするビューを示します。
2)OnSwipeラベル。これは、アニメーションがユーザーの軽いタッチによって制御されることを示すもので、ちょっとしたジェスチャー・スライディングのような感覚です。
- app:touchAnchorIdは、スライドとドラッグが可能なビューを示します。
- app:touchAnchorSideどちら側からドラッグを開始するかを示します。
- app:dragDirectionはドラッグの進行方向を示します。例えば、dragRight は右にドラッグする場合を示します。
- app:onTouchUpはジェスチャーが上げられた時の動作を表します。例えば、stop はジェスチャーが上げられたときにビューのアニメーションが停止することを意味します。
3)java コード制御.
motionLayout.transitionToEnd()アニメーションを終了位置まで遷移させます。motionLayout.setTransitionListener,モニターアニメーション。
ここでは、Houyiをクリックするとアニメーションが始まるように設定しています:
<OnClick
app:clickAction="toggle"
app:targetId="@id/houyi" />
鳳翼をクリックすると、鳳翼の矢が放たれました。
しかし、これは十分ではありません、アーサーの位置へのHouyi矢印は確かに消えますが、どのようにこの消失を示すのですか?透明度を使用して、直接0に終了位置の透明度を設定すると消えます。
android:alpha="0"
効果を見てください:
矢が空中にある間に消えるのはまだ少し間違っているようです。望ましい効果は、矢がアーサーに当たったときに消えることです。というのも、アニメーションの生成は、始点から終点への遷移の流れに各時点で均等に従うので、彼は始点から完全に消えるまで、ゆっくりと直線的に透明度を変化させるだけだからです。
どうしますか?キーフレームKeyFrameSetを使ってみましょう。
KeyFrameアニメーション中にキーの位置やプロパティを設定するキーフレームを設定します。キーフレームを設定すると、MotionLayoutはビューを開始点から各中間点、そして最終的なターゲット位置までスムーズに移動させます。
そこで、ここでは2つの重要なプロパティを設定する必要があります:
1) アーサーを射ようとするとき、矢の透明度は1のまま。
2) アーサーを射るとき、透明度は0に変更されます。
<KeyFrameSet>
<KeyAttribute
app:framePosition="98"
app:motionTarget="@id/houyi_arrow"
android:alpha="1" />
<KeyAttribute
app:framePosition="100"
app:motionTarget="@id/houyi_arrow"
android:alpha="0" />
</KeyFrameSet>
KeyAttributeは、キー属性を設定するタグです。
- app:framePositionこのキーフレームの位置をパーセンテージで示します。
- app:motionTargetは、どのビューで動作するかを示します。
これでセットアップが完了し、鳳翼の矢のアニメーションが完成しました。
クレイジー・ウォーキング・アーサー
アーサーに関して言えば、アーサーのアニメーション効果は撃たれる位置から歩き出すことです。そこで、まずアーサーの位置を設定し、遠くから撃たれる位置まで歩きます。
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@+id/houyi_arrow"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_marginLeft="190dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.8">
</Constraint>
<Constraint
android:id="@+id/yase"
android:layout_width="66dp"
android:layout_height="66dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.8"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.2">
</Constraint>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/houyi_arrow"
android:layout_width="66dp"
android:layout_height="66dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.65"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.35">
</Constraint>
<Constraint
android:id="@+id/yase"
android:layout_width="66dp"
android:layout_height="66dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.65"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.35">
</Constraint>
</ConstraintSet>
ご覧のように、エンドポイントの状態では、複数のコントロールプロパティを配置することができます。
アーサーのスタートとエンドの状態を取得し、クレイジーウォークを設定するには?--キーサイクル
KeyCycleは、キーフレームを循環させることで、アニメーションに振動を加えることができます。 この振動は、実際にはsinやcosのような波形グラフです。また、KeyFrameSetタブの下に置かれています。
<KeyCycle
android:translationY="50dp"
app:framePosition="70"
app:motionTarget="@id/yase"
app:wavePeriod="0.5"
app:waveShape="sin" />
- app:waveShape波の種類を示します(例:sin、cos)。
- app:wavePeriodは波の周期を表します。例えば、0.5は半分のsin周期を意味し、0.5倍の振動と理解できます。
さて、最初のシーンが終わりました:
シーン2
操作方法:大慈、中武燕
Animation Description: 草むらから出てくる大慈と中武燕。
このシーンは主に、草むらにしゃがんでいた大慈と中武燕が、侯毅が矢を射るのを見て、技を受けようと草むらから出てくる様子を描いています。コードに直接
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/motionLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/scene_02"
tools:showPaths="true">
<ImageView
android:id="@+id/daji"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/daji_model" />
<ImageView
android:id="@+id/zhongwuyan"
android:layout_width="75dp"
android:layout_height="75dp"
android:src="@drawable/zhongwuyan_model" />
</androidx.constraintlayout.motion.widget.MotionLayout>
//scene_02.xml
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://..com/apk/res/android"
xmlns:app="http://..com/apk/res-auto">
<Transition
app:constraintSetEnd="@+id/end"
app:constraintSetStart="@+id/start"
app:duration="2000">
<OnClick
app:clickAction="toggle"
app:targetId="@id/daji" />
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@+id/daji"
android:layout_width="80dp"
android:layout_height="80dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.75"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.85">
</Constraint>
<Constraint
android:id="@+id/zhongwuyan"
android:layout_width="70dp"
android:layout_height="70dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.25"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.1">
</Constraint>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/daji"
android:layout_width="80dp"
android:layout_height="80dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.65"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.65">
</Constraint>
<Constraint
android:id="@+id/zhongwuyan"
android:layout_width="70dp"
android:layout_height="70dp"
android:alpha="0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.42"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.2">
</Constraint>
</ConstraintSet>
</MotionScene>
ここでは、中武燕にエイリアンのような歩き方をさせたいと思います。ここでもう1つのキーフレーム・タグ、KeyPositionを使います。
KeyPosition はキーフレームの位置を表し、アニメーションが必ず通過するポイントです。このプロパティは、デフォルトのモーションパスを調整するために使用されます。
2) keyPositionTypeには3つの設定があります。
- parentRelative、親ビューの位置からの相対位置、xは横軸、yは縦軸 例えば、位置を右端の中央に設定するには、app:percentY="0.5" app:percentX="1 "とします。
- deltaRelativeは、モーションシーケンス全体を通してビューが移動した距離に対する相対値で、ビューの開始位置、終了位置です。
bellwetherのparentRelativeです。
<KeyPosition
app:motionTarget="@id/zhongwuyan"
app:framePosition="30"
app:keyPositionType="parentRelative"
app:percentY="0"
app:percentX="0.4"
/>
最後に、2人のヒーローが茂みから出てきて、半透明から不透明になるのを追加します:
<KeyAttribute
app:framePosition="0"
app:motionTarget="@id/daji"
android:alpha="0.7" />
<KeyAttribute
app:framePosition="70"
app:motionTarget="@id/daji"
android:alpha="1" />
<KeyAttribute
app:framePosition="0"
app:motionTarget="@id/zhongwuyan"
android:alpha="0.7" />
<KeyAttribute
app:framePosition="60"
app:motionTarget="@id/zhongwuyan"
android:alpha="1" />
シーン3
操作方法:大地の第一スキル、大地の第二スキル、中武燕
動画内容: 中武燕が群衆の中に閃光を放ち、大技で回転、大慈の第二技でルーバンを気絶させ、第一技で追撃。
中武燕のフラッシュには、アルファ値を変更する消失と再出現を使いました。 中武燕の動きには、Y軸周りの回転を設定するandroid:rotationYを使いました。
//scene_03.xml
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://..com/apk/res/android"
xmlns:app="http://..com/apk/res-auto">
<Transition
app:constraintSetEnd="@+id/end"
app:constraintSetStart="@+id/start"
app:duration="4000">
<KeyFrameSet>
<!-- 中武燕>
<KeyAttribute
app:framePosition="20"
app:motionTarget="@id/zhongwuyan2"
android:rotationY="0" />
<KeyAttribute
app:framePosition="1"
app:motionTarget="@id/zhongwuyan"
android:alpha="1" />
<!-- 大治2年の技>
<KeyPosition
app:motionTarget="@id/daji_2"
app:framePosition="20"
app:keyPositionType="deltaRelative"
app:percentY="0"
app:percentX="0"
/>
<KeyAttribute
app:framePosition="20"
app:motionTarget="@id/daji_2"
android:alpha="1" />
<KeyPosition
app:motionTarget="@id/daji_2"
app:framePosition="60"
app:keyPositionType="deltaRelative"
app:percentY="1"
app:percentX="1"
/>
<KeyAttribute
app:framePosition="40"
app:motionTarget="@id/daji_2"
android:alpha="1" />
<KeyAttribute
app:framePosition="61"
app:motionTarget="@id/daji_2"
android:alpha="0" />
<!-- ダジ1スキル>
<KeyAttribute
app:framePosition="55"
app:motionTarget="@id/daji_1"
android:alpha="1" />
<KeyPosition
app:motionTarget="@id/daji_1"
app:framePosition="55"
app:keyPositionType="deltaRelative"
app:percentY="0"
app:percentX="0"
/>
<KeyAttribute
app:framePosition="85"
app:motionTarget="@id/daji_1"
android:alpha="1" />
</KeyFrameSet>
<OnClick
app:clickAction="toggle"
app:targetId="@id/zhongwuyan2" />
</Transition>
//
</MotionScene>
ソースコードの全文をご覧になりたい方は、記事の最後にある添付ファイルをご覧ください。
実用化のシナリオ
実際には、ダウンを行うことができます見つけることができる、Motionlayoutは本当に非常にシンプルなアニメーションを実現するために、大幅にjetpackのコンポーネント開発の当初の意図でもある開発効率を向上させます。しかし、Motionlayoutはまだ欠点があるなど、直接ケース内のxmlコードを介して、関節のアニメーションを設定することはできません、アニメーションのシーケンスを設定します。だから最後に、motionlayoutアプリケーションのシナリオは何ですか?
motionlayoutは遷移アニメーションとして、コントロールの切り替えやインターフェイスの変更、その他のアニメーションに適用します。DrawerLayout,viewpager例えば、スイッチ時に、いくつかのビューの遷移アニメーションを設定することができます。公式サイトでは、モーションアニメーションの同様のYouTubeのケースを持って、私は簡単に言うためにこっちに移動します。最初の効果
このアニメーション効果を30分もしないうちにやってしまうなんて、頭痛がします。さて、MotionLayout:とても簡単です。
一緒に分析しましょう:
含まれるコントロール:トップレイアウトのtopLayout、ミッドレイアウトのmidlayout、ボトムメニューのbottomView。
アニメーションの説明
- topLayoutは、上の親の位置に依存していたのを、下のbottomViewの上に来るように変更します。高さは320dpから54dpに変更されます。
- topImageは、親レイアウトがいっぱいになった状態から、最終的な長さがいっぱいにならず、高さが親レイアウトの上下に2dpずつ移動します。 keyframe: 90%進んだ時点では、まだいっぱいになっていて、その後ゆっくりと長さが縮んでいきます。
- topPlay、topCloseが表示されていない状態から、最終的に完全に表示されるようになりました。キーフレーム:進行度90%の時点では、不透明度はまだ10%(alpha0.1)ですが、その後徐々に不透明になります。
- midlayout、白いレイアウト、従属親レイアウトの下からbottomViewの上へ、このレイアウトは、topplayoutダウンより自然にすることです、recycleviewが完全に透明になるため、この白いレイアウトの遷移が必要です、アニメーションがより完全であるように。
- midView、topplayoutの下の位置からtopplayoutと最終的に重なるまでの透明度を不透明から完全透明にします。キーフレーム:進行度75%まで、完全透過。
- bottomView、親レイアウトビューの下から親レイアウトの一番下まで
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://..com/apk/res/android"
xmlns:motion="http://..com/apk/res-auto">
<Transition
motion:constraintSetEnd="@+id/end"
motion:constraintSetStart="@+id/start"
motion:duration="1000"
motion:motionInterpolator="linear">
<OnSwipe
motion:dragDirection="dragUp"
motion:touchAnchorId="@+id/top_image_container"
motion:touchAnchorSide="bottom" />
<KeyFrameSet>
<KeyPosition
motion:curveFit="linear"
motion:framePosition="90"
motion:motionTarget="@id/top_image"
motion:percentWidth="0"
motion:percentX="0" />
<KeyPosition
motion:curveFit="linear"
motion:framePosition="90"
motion:motionTarget="@id/top_image_container"
motion:percentWidth="0" />
<KeyPosition
motion:curveFit="linear"
motion:framePosition="90"
motion:motionTarget="@id/recyclerview_container"
motion:percentWidth="0" />
<KeyAttribute
android:alpha="0"
motion:framePosition="75"
motion:motionTarget="@id/recyclerview_front" />
<KeyAttribute
android:alpha="0.10"
motion:framePosition="90"
motion:motionTarget="@id/image_clear" />
<KeyAttribute
android:alpha="0.10"
motion:framePosition="90"
motion:motionTarget="@id/image_play" />
</KeyFrameSet>
</Transition>
</MotionScene>
ここで、いくつかの新しい属性についてお話ししましょう:
- motion:curveFit(モーション:カーブフィット)は、そのキーフレームを通過するためにどの直線軌道が使われるかを示します。これは直線の遷移のために線形に設定され、それ自体が直線であるため、何の効果もありません。
- motion:percentWidthは、ビューの相対的な大きさを表し、値は0〜1で、0は初期位置の幅を表し、1は終了位置の幅を表します。値が 0 の場合、ビューの幅は初期位置の幅のままです。
motion:motionInterpolatorはアニメーションの補間子を表します。linearは直線的な動きで、バウンススプリングモーションなども設定できます。
トランジション・アニメーションについて
トランジションアニメーションについては、実際には、また、存在する - TransitionManager。 TransitionManagerは、トランジション遷移アニメーション間の異なるシーンを提供することができます、あなたは2つのシーンを設定する必要があり、対応するコントロールIDで2つのシーンに対応します。最後に、遷移アニメーションは、Javaコードで実行されます。
前のコード
//つのシーンのレイアウト
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scene_root">
<include layout="@layout/a_scene" />
</FrameLayout>
//
<LinearLayout xmlns:android="http://..com/apk/res/android"
android:id="@+id/scene_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="26sp"
android:id="@+id/text_view1"
android:text="Text Line 1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="26sp"
android:id="@+id/text_view2"
android:text="Text Line 2" />
</LinearLayout>
//
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://..com/apk/res/android"
android:id="@+id/scene_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text_view2"
android:textSize="22sp"
android:text="Text Line 2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:id="@+id/text_view1"
android:text="Text Line 1" />
</LinearLayout>
//シーンを取得し、シーン間のアニメーションを開始し、シーン1からシーン2に変わる。
val sceneRoot: ViewGroup = findViewById(R.id.scene_root)
val aScene: Scene = Scene.getSceneForLayout(sceneRoot, R.layout.a_scene, this)
val anotherScene: Scene = Scene.getSceneForLayout(sceneRoot, R.layout.another_scene, this)
titletv.setOnClickListener {
TransitionManager.go(anotherScene)
}
はぁ、そしてMotionLayoutはまだ非常に似ている、アイデアは似ている、遷移アニメーションを完了するには、コントロールの異なるシーンを介しています。その後、疑問が生じるので、なぜMotionLayoutがあるのですか?
- 前者の場合、キーフレームを設定することはできず、アニメーションの状態は2つしかありません。一方、MotionLayoutでは、位置やアトリビュートなどを変えて、自由にキーフレームを設定できます。
- 前者はジェスチャーに追従できず、MotionLayoutの方がはるかにスムーズです。
- MotionLayoutはすべてxmlコードでアニメーションを完成させることができ、Javaコードを一行呼び出す必要はありません。
- 前者はレイアウト・コントロールの重複が多く、重複するコントロールを記述するために異なるxmlファイルを必要とします。
ですから、MotionLayoutは今でも素晴らしいものです!
添付ファイル
記事関連ソースコード
さようなら、あなたからの1つのが、。
- 終了




