Kalpesh Rajai
Kalpesh Rajai

Reputation: 2056

Android button effects and animation

In my next project i want button effect or animation like this when user click on button or drag hover the button.

I do too many research but i found nothing.

I want button effect like this.

enter image description here

Please help me to solve this.

Thanks in advance.

Upvotes: 1

Views: 3913

Answers (3)

Danial Hussain
Danial Hussain

Reputation: 2530

I think you should use "FrameLayout" clickable and also inside it use imageview and you then easily animate the image.

Structure

<FrameLayout
 //set the properties + must set clickable property  
>
   <ImageView 
    // Set the required property 
   />
</FrameLayout>

Then set click Listener of framelayout and where you need to animate imageview inside .java file.

Create a animatation xml in anim folder

my_anim.xml

<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite" />

then call this in .java file with the imageview like given below for smooth rotation of image.

 Animation a = AnimationUtils.loadAnimation(getActivity(), R.anim.my_anim);

            a.setDuration(1000);

            myImageView.startAnimation(a);


            a.setInterpolator(new Interpolator() {

                private final int frameCount = 50;

                @Override
                public float getInterpolation(float input) {

                    return (float) Math.floor(input * frameCount) / frameCount;

                }
            });

Upvotes: 2

Ivan
Ivan

Reputation: 3062

To create animation similar to your example you will definitely need to implement custom animations. Find details here:

https://developer.android.com/training/material/animations.html

Also you should definitely check for existing libraries that might imlement similar effects. Nice libraries source:

https://android-arsenal.com/tag/13

Upvotes: 4

Osman Goni Nahid
Osman Goni Nahid

Reputation: 1279

Here is basic animation for button effect : http://android-er.blogspot.com/2012/02/apply-animation-on-button.html

Upvotes: 3

Related Questions