Lakhan Sharma
Lakhan Sharma

Reputation: 1731

Move button randomly on screen android

I am new to android developement.I want to have a singlebutton on the screen that continuously move. When it touches the sides,it should bounce back.and when clicked opens activity. How do i do this? Any helpful links? Ideas? Thanks!

Upvotes: 2

Views: 1075

Answers (1)

ashish.n
ashish.n

Reputation: 1224

for moving button you need to use animation here is snipplet of it

TranslateAnimation  mAnimation = new TranslateAnimation(
                            TranslateAnimation.RELATIVE_TO_PARENT, 1f,
                            TranslateAnimation.RELATIVE_TO_PARENT, -1.2f,
                            TranslateAnimation.ABSOLUTE, 0f,
                            TranslateAnimation.ABSOLUTE, 0f
                           );
                   mAnimation.setDuration(15000);
                   mAnimation.setRepeatCount(-1);
                   mAnimation.setRepeatMode(Animation.INFINITE);
                   mAnimation.setInterpolator(new LinearInterpolator());
                   mAnimation.setFillAfter(true);

                    LinearLayout alertlayout = (LinearLayout) findViewById(R.id.alertll);
                    alertlayout.startAnimation(mAnimation);

and for opening a new activity

Intent intent = new Intent(YourActivity.this,NewActivity.class);
StartActivity(intent);

Upvotes: 1

Related Questions