Zoom in animation with Bounce on Button Click in Android Studio

How to set Android ZooM in animation with Bounce in Andriod Studio

Andriod zoom in bounce animation 

Step 1: 
Create an anim folder in res. Also create a file in anim folder named zoomin_bounce. If you don't know how to creat anim folder and files in it. Just visit here to learn.



2. zoomin_bounce.xml


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/bounce_interpolator">

    <scale
        android:duration="1000"
        android:fromXScale="1"
        android:fromYScale="0.5"
        android:pivotX="50%"
        android:pivotY="0%"
        android:toXScale="1.0"
        android:toYScale="1.0"
        android:repeatCount="3"/>

    <alpha
        android:duration="600"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />

</set>

If you don't want the repeat, you can remove the  android:repeatCount="3" .


3.activity_main.xml


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.hp.symonapps.MainActivity"
    android:orientation="vertical"
    android:gravity="center">


    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/iv"
        android:src="@drawable/ss2"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Zoom In With Bounce"
        android:id="@+id/b_zoom"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="45dp"
        android:textSize="21sp"
        android:padding="20dp"/>


</LinearLayout>






3. MainActivity.java


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.example.hp.symonapps;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;


public class MainActivity extends AppCompatActivity {

    Button b_zoom;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        b_zoom = (Button) findViewById(R.id.b_zoom); //cast the b_zoom button
        b_zoom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


                ImageView iv=(ImageView)findViewById(R.id.iv); //cast the iv imageView button
                Animation anim=AnimationUtils.loadAnimation(MainActivity.this, R.anim.zoomin_bounce);
                iv.setAnimation(anim);


            }
        });





    } //onCreate end


}

Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hey there! I know this is kind of off-topic, but I’d figured I’d ask. Would you be interested in exchanging links or maybe guest authoring a blog post or vice-versa? My blog goes over a lot of the same topics as yours, and I believe we could greatly benefit from each other. If you happen to be interested, feel free to shoot me an e-mail. I look forward to hearing from you! Great blog by the way!
    Surya Informatics

    ReplyDelete

Post a Comment