序文
メニューが上部からポップインしてから下から消えるメニューを実装します。トップが飛び込むと、上下を振るプロセスがあります。底が消えたら、最初にスライドしてから、下にスライドしてから消えます。
レンダリングは次のとおりです。
依存関係を紹介します
実装 'com.android.support:support-dynamic-animation:27.1.1'1
Springanimationを作成するには、3つのパラメーターが必要です。
•アニメーションビュー
•ダイナミカン化タイプ
alpharotationRotation_xrotation_yscale_xscale_yscroll_xscroll_ytranslation_xtranslation_ytranslation_zxyz
上記のGIF図は、DynamicAnimation Translation_yを使用したプレビュー図です。次に、パラメーターを回転に設定します。
springanimation signupbtnanimy = new springanimation(constraintlayout、dynamicanimation.rotation、0);
レンダリングは次のとおりです。
- アニメーションを作成するための最終的な場所
ビューの現在の位置に対するオフセット。
Springforce
アニメーションをスムーズで弾力性のあるパラメーターを設定する必要があります。
- こわばり
つまり、こわばり。この値が大きいほど、内側の部分が大きくなるほど、アニメーションの弾力性効果が明らかになり、動きが速くなります。
stiffness_highstiffness_lowstiffness_mediumstiffness_very_low
設定方法は次のとおりです。
SignupBtnanimy.getSpring()。setStiffness(springforce.stiffness_low);
•減衰減衰率
つまり、減衰率、この値が大きいほど、スプリング効果が速く停止します
damping_ratio_high_bouncydamping_ratio_low_bouncydamping_ratio_medium_bouncydamping_ratio_no_bouncy
設定方法は次のとおりです。
SignupBtnanimy.getSpring()。setDampingratio(springforce.damping_ratio_medium_bouncy);
startvelocity
起動速度、デフォルトの速度は0、ユニットはPX/秒です。
全体のコードは次のとおりです。
•メニューアニメーションを表示します
public void showanimal(){setVisibility(view.visible); springanimation signupbtnanimy = new springanimation(constraintlayout、dynamicanimation.translation_y、0); SignupBtnanimy.getSpring()。setStiffness(springforce.stiffness_low); SignupBtnanimy.getSpring()。setDampingratio(springforce.damping_ratio_medium_bouncy); SignupBtnanimy.setStartVelocity(5000); SignupBtnanimy.start(); }•メニューアニメーションを非表示にします
public void hideanimal(){height =(screentools.getScreenheight(getContext())-constraintlayout.getheight()) / 2 + constraintlayout.getheight() + screentools.dp2px(getContext()、50); ObjectAnimator Animator = objectAnimator.Offloat(constraintlayout、 "Translation"、0f、-100f、height); Animator.setDuration(600); Animator.setInterPolator(new DeceleretInterPolator()); Animator.AddListener(new AnimatorListenerAdapter(){@Override public void onanimationEnd(Animator Animation){super.onanimationEnd(animation); setVisibility(gon); lerayout();}}); Animator.start(); }ソースコード:https://github.com/lsnumber1/studyspringanimation
要約します
上記は、Springanimationの実装メニューが上からポップアップし、下から消えます。私はそれが誰にでも役立つことを願っています。ご質問がある場合は、メッセージを残してください。編集者は、すべての人に時間内に返信します。 wulin.comのウェブサイトへのご支援ありがとうございます!