Full project with source code how to use the AndroidViewAnimation library, which makes it very easy to animate views with lots of different kinds of animations. We can also change the duration of those animations and choose to repeat them
Gradle
dependencies {
implementation 'com.daimajia.androidanimations:library:2.4@aar'
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="tech.codingpoint.androidviewanimationsexample.MainActivity">
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Hello World!"
android:textSize="30sp" />
<Button
android:id="@+id/button_animate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="47dp"
android:text="animate" />
</RelativeLayout>
MainActivity.java
package tech.codingpoint.androidviewanimationsexample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;
public class MainActivity extends AppCompatActivity {
private TextView mTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextView = findViewById(R.id.text_view);
Button buttonAnimate = findViewById(R.id.button_animate);
buttonAnimate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
YoYo.with(Techniques.Tada)
.duration(700)
.repeat(1)
.playOn(mTextView);
}
});
}
}