Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the Animation effect of Flip Card by android

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report