Applying animation on text in android
The code below applies an animation on text on a textviewCreate a folder called anim inside the res folder and then create the following xml inside the anim folder.
This is the xml which animates the text.
textanim.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator"> <scale android:fromXScale="1.0" android:toXScale="0.8" android:fromYScale="1.0" android:toYScale="1.2" android:pivotX="50%" android:pivotY="50%" android:duration="200" android:repeatCount="4" android:repeatMode="reverse" /></set>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
android:text="Merry Christmass"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ACC437"
android:textStyle="bold" />
</LinearLayout>
MainActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView myText;
Animation myAnimation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myText = (TextView)findViewById(R.id.textView1);
myAnimation = AnimationUtils.loadAnimation(this, R.anim.textanim);
myText.startAnimation(myAnimation);
// myText.setOnClickListener(new OnClickListener(){
//
// @Override
// public void onClick(View arg0) {
//
// }});
}
}
0 comments:
Post a Comment