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 simple active turntable by android

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

Share

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

This article mainly introduces android how to achieve a simple activity turntable, the article introduces in great detail, has a certain reference value, interested friends must read it!

The details are as follows

Page

Public class CircleTurntableActivity extends AppCompatActivity {private Animation mStartAnimation; private ImageView mLuckyTurntable; private boolean isRunning; private boolean mIsLucky = false; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_circle_turntable); mLuckyTurntable = (ImageView) findViewById (R.id.id_lucky_turntable); ImageView mStartBtn = (ImageView) findViewById (R.id.id_start_btn) MStartBtn.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {if (! isRunning) {isRunning = true; mIsLucky =! mIsLucky; startAnimation ();}) } / * Open animation * 5 seconds rotate 5 times + winning position angle * / private void startAnimation () {float toDegree;// end angle (calculated based on the actual turntable diagram) if (mIsLucky) {toDegree = 360 * 5 + 30f;} else {toDegree = 360 * 5 + 90f } if (mStartAnimation! = null) {mStartAnimation.reset () Parameters: rotation start angle, rotation end angle, X axis expansion mode, X axis expansion value, Y axis expansion mode, Y axis expansion mode, Y coordinate expansion value mStartAnimation = new RotateAnimation (0, toDegree, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mStartAnimation.setDuration (5000) / / set the rotation time mStartAnimation.setRepeatCount (0); / / set the number of repeats mStartAnimation.setFillAfter (true); / / whether to stay in the finished state after the execution of the animation mStartAnimation.setInterpolator (new AccelerateDecelerateInterpolator ()) / / mStartAnimation.setAnimationListener (new Animation.AnimationListener () {@ Override public void onAnimationStart (Animation animation) {} @ Override public void onAnimationEnd (Animation animation) {isRunning = false; Toast.makeText (CircleTurntableActivity.this, mIsLucky?) "Beautiful gifts": "Thank you for your participation", Toast.LENGTH_SHORT). Show ();} @ Override public void onAnimationRepeat (Animation animation) {}}); mLuckyTurntable.startAnimation (mStartAnimation);}}

Page layout

Effect:

The above is all the contents of the article "how to achieve a simple activity turntable in android". Thank you for reading! Hope to share the content to help you, more related 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