How to realize simple active turntable by android
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!