Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-------------- strings.xml -----------------------
- <resources>
- <string name="app_name">Animation Project</string>
- <string name="my_walker">My Walker</string>
- <string name="bye_walker">Bye Bye!</string>
- <string name="go">Go!</string>
- <string name="animation">animation</string>
- </resources>
- //----------------- simple_animation.xml ---------------------
- <?xml version="1.0" encoding="utf-8"?>
- <animation-list xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:drawable="@drawable/a1" android:duration="100" />
- <item android:drawable="@drawable/a2" android:duration="100" />
- <item android:drawable="@drawable/a3" android:duration="100" />
- <item android:drawable="@drawable/a4" android:duration="100" />
- <item android:drawable="@drawable/a5" android:duration="100" />
- <item android:drawable="@drawable/a6" android:duration="100" />
- <item android:drawable="@drawable/a7" android:duration="100" />
- <item android:drawable="@drawable/a8" android:duration="100" />
- <item android:drawable="@drawable/a9" android:duration="100" />
- <item android:drawable="@drawable/a10" android:duration="100" />
- <item android:drawable="@drawable/a11" android:duration="100" />
- <item android:drawable="@drawable/a12" android:duration="100" />
- <item android:drawable="@drawable/a13" android:duration="100" />
- <item android:drawable="@drawable/a14" android:duration="100" />
- <item android:drawable="@drawable/a15" android:duration="100" />
- <item android:drawable="@drawable/a16" android:duration="100" />
- <item android:drawable="@drawable/a17" android:duration="100" />
- <item android:drawable="@drawable/a18" android:duration="100" />
- <item android:drawable="@drawable/a19" android:duration="100" />
- <item android:drawable="@drawable/a20" android:duration="100" />
- <item android:drawable="@drawable/a21" android:duration="100" />
- <item android:drawable="@drawable/a22" android:duration="100" />
- <item android:drawable="@drawable/a23" android:duration="100" />
- <item android:drawable="@drawable/a24" android:duration="100" />
- </animation-list>
- //---------------------- animate.xml ----------------------------------
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android">
- <translate
- android:duration="5000"
- android:fromXDelta="80%p"
- android:toXDelta="-5%p" />
- <scale
- android:duration="1000"
- android:fromXScale="1"
- android:fromYScale="1"
- android:pivotX="50%"
- android:pivotY="50%"
- android:toXScale="-1"
- android:toYScale="1"
- android:startOffset="4000" />
- <translate
- android:duration="5000"
- android:fromXDelta="-5%p"
- android:toXDelta="120%p"
- android:startOffset="5000" />
- </set>
- //------------------------- activity_main.xml ----------------------------
- <?xml version="1.0" encoding="utf-8"?>
- <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <TextView
- android:id="@+id/title"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textSize="32sp"
- android:gravity="center"
- android:layout_marginTop="50dp"
- android:text="@string/my_walker" />
- <TextView
- android:id="@+id/bye"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textSize="44sp"
- android:gravity="center"
- android:layout_marginTop="50dp"
- android:textColor="@color/colorPrimary"
- android:text="@string/bye_walker" />
- <ImageView
- android:id="@+id/imageView"
- android:layout_width="150dp"
- android:layout_height="150dp"
- android:layout_marginTop="100dp"
- android:layout_gravity="start"
- android:contentDescription="@string/animation"
- app:srcCompat="@drawable/simple_animation" />
- <Button
- android:id="@+id/btnRun"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textSize="28sp"
- android:layout_margin="40dp"
- style="@style/Widget.AppCompat.Button.Colored"
- android:layout_marginBottom="50dp"
- android:text="@string/go" />
- </LinearLayout>
- </androidx.constraintlayout.widget.ConstraintLayout>
- // ------------------------ MainActivity.java ------------------------
- package com.sgl.animationproject;
- import androidx.annotation.InterpolatorRes;
- import androidx.appcompat.app.AppCompatActivity;
- import android.content.Context;
- import android.graphics.Interpolator;
- import android.graphics.drawable.AnimationDrawable;
- import android.os.Bundle;
- import android.view.View;
- import android.view.animation.AlphaAnimation;
- import android.view.animation.Animation;
- import android.view.animation.AnimationUtils;
- import android.widget.ImageView;
- import android.widget.TextView;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity implements Animation.AnimationListener {
- ImageView imageView;
- Context context;
- AnimationDrawable animationDrawable;
- AnimationDrawable textDrawable;
- TextView textView;
- Animation animation;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- setPointer();
- }
- private void setPointer() {
- this.context = this;
- imageView = findViewById(R.id.imageView);
- textView = findViewById(R.id.bye);
- animationDrawable = (AnimationDrawable)imageView.getDrawable();
- textView.setVisibility(View.INVISIBLE);
- imageView.setVisibility(View.INVISIBLE);
- findViewById(R.id.btnRun).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- imageView.setVisibility(View.INVISIBLE);
- animationDrawable.start();
- imageView.startAnimation(animation);
- }
- });
- animation = AnimationUtils.loadAnimation(context, R.anim.animate);
- animation.setAnimationListener(this);
- }
- @Override
- public void onAnimationStart(Animation animation) {
- Toast.makeText(context, "Animation Started", Toast.LENGTH_LONG).show();
- }
- @Override
- public void onAnimationEnd(Animation animation) {
- textView.setVisibility(View.VISIBLE);
- AlphaAnimation fadeIn = new AlphaAnimation(0.0f, 1.0f);
- // AlphaAnimation fadeOut = new AlphaAnimation(1.0f, 0.0f);
- textView.startAnimation(fadeIn);
- fadeIn.setDuration(1200);
- fadeIn.setFillAfter(true);
- Toast.makeText(context, "Animation Ended", Toast.LENGTH_LONG).show();
- }
- @Override
- public void onAnimationRepeat(Animation animation) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement