Open top menu





Exaplain- Tween Animation define an xml that perform transition such as rotating,move and stretching etc.

hyprespasce_one_anim.xml
............................................................................................................
xml version="1.0" encoding="utf-8"?>
<set android:shareInterpolator="false"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
       
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:fromXScale="1.0"
        android:toXScale="1.4"
        android:fromYScale="1.0"
        android:toYScale="0.6"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fillAfter="false"
        android:duration="700" />
    <set android:interpolator="@android:anim/decelerate_interpolator">
        <scale
           
android:fromXScale="1.4"
            android:toXScale="0.0"
            android:fromYScale="0.6"
            android:toYScale="0.0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:startOffset="700"
            android:duration="400"
            android:fillBefore="false" />
        <rotate
           
android:fromDegrees="0"
            android:toDegrees="-45"
            android:toYScale="0.0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:startOffset="700"
            android:duration="400" />
    </set>
</set>



............................................................................................................
 
activity_main.xml
............................................................................................................
xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
       
android:id="@+id/img_animation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="42dp"
        android:src="@drawable/log_icon" />
    
    <Button
       
android:text="Start Move"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/button" />

</RelativeLayout>


............................................................................................................

MainActivity.java
............................................................................................................
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
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 {
    Animation animTogether;
    ImageView img_animation;
    @Override
   
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        img_animation= (ImageView) findViewById(R.id.img_animation);
        Button btn=(Button) findViewById(R.id.button);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
           
public void onClick(View v) {


                 ObjectAnimator animX = ObjectAnimator.ofFloat(img_animation, "x", 100f);
                 ObjectAnimator animY = ObjectAnimator.ofFloat(img_animation, "y", 100f);
                 AnimatorSet animSetXY = new AnimatorSet();
                 animSetXY.playTogether(animX, animY);
                 animSetXY.start();


                animTogether = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.hyprespace_one_anim);
                img_animation.startAnimation(animTogether);

            }
        });
    }
}


............................................................................................................




Tagged

0 comments