Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the Animation effect of Flip Card by android

Shulou Source: shulou.com Published: 2022-06-02 12:42:56 11月08日 Update

Editor to share with you how to achieve android flip card animation effect, I believe that most people do not know much, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Home page

The home page consists of two cards on the front and back, and at the same time, set the click event flipCard.

Logic, initialize animation and shot distance.

@ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); ButterKnife.bind (this); setAnimators (); / / set animation setCameraDistance (); / / set lens distance}

Animation

Initialize right-out (RightOut) and left-in (LeftIn) animations, using the animation collection AnimatorSet.

When the right-out animation starts, the click event is invalid, and when the left-in animation ends, the click event resumes.

/ / animate private void setAnimators () {mRightOutSet = (AnimatorSet) AnimatorInflater.loadAnimator (this, R.animator.anim_out); mLeftInSet = (AnimatorSet) AnimatorInflater.loadAnimator (this, R.animator.anim_in); / / set click event mRightOutSet.addListener (new AnimatorListenerAdapter () {@ Override public void onAnimationStart (Animator animation) {super.onAnimationStart (animation); mFlContainer.setClickable (false)) ); mLeftInSet.addListener (new AnimatorListenerAdapter () {@ Override public void onAnimationEnd (Animator animation) {super.onAnimationEnd (animation); mFlContainer.setClickable (true);}});}

Right out of animation

Rotate 180 °. When rotated in half, the card disappears.

Enter the animation on the left

At the beginning is hidden, reverse rotation, when half of the rotation, the card is displayed.

Lens angle of view

To change the viewing angle, it involves rotating the Y axis of the card, namely rotationY, and the viewing distance needs to be changed.

If it is not modified, it will exceed the height of the screen and affect the visual experience.

/ / change the viewing distance, close to the screen private void setCameraDistance () {int distance = 16000; float scale = getResources (). GetDisplayMetrics (). Density * distance; mFlCardFront.setCameraDistance (scale); mFlCardBack.setCameraDistance (scale);}

Rotation control

Set the right-out and left-in animation target controls, the two animations are carried out synchronously, and distinguish the positive and negative sides up.

/ / flip card public void flipCard (View view) {/ / face up if (! mIsShowBack) {mRightOutSet.setTarget (mFlCardFront); mLeftInSet.setTarget (mFlCardBack); mRightOutSet.start (); mLeftInSet.start (); mIsShowBack = true;} else {/ / back up mRightOutSet.setTarget (mFlCardBack); mLeftInSet.setTarget (mFlCardFront) MRightOutSet.start (); mLeftInSet.start (); mIsShowBack = false;}}

Animation effect

The above is all the content of this article "how to realize the animation effect of flip card in android". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Animation cards events perspective effects articles shots content screen front home page not much two at the same time most controls more goals knowledge industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Information MySQL MariaDB Xiaomi