How to set Android Flip Animation in vertically

Let's see how to set Vertical flip animation in android.

Android flip animation


Create a xml file in anim folder. Then name it flip_v.





 flip_v.xml


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:fromXScale="1.0"
        android:toXScale="1.0"
        android:fromYScale="1.0"
        android:toYScale="-1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="400"
        android:repeatMode="reverse"
        android:repeatCount="24"

     />
</set>

Xscale  is  horizontal
Yscale is vertical.

We can reduce duration for fast and increase to load slowly.
repeatCount will repeat the animation as you set the value. Here I set it 24. As a result it will repeat 24 times.


duration  is the Amount of time for the animation to run which set in millisecond.





 activity_main.xml


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
<?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"/>


</LinearLayout>



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
package com.example.hp.symonapps;

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


public class MainActivity extends AppCompatActivity {



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


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




    } //onCreate end


}

Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot
    Surya Informatics

    ReplyDelete

Post a Comment