Ticker

6/recent/ticker-posts

Apply animation on TextView

Apply animation on TextView


To create animation, create xml file to define animation in /res/anim/ folder, /res/anim/myanimation.xml.

android:interpolator="@android:anim/linear_interpolator">
android:fromXScale="1.0"
android:toXScale="0.8"
android:fromYScale="1.0"
android:toYScale="1.2"
android:pivotX="50%"
android:pivotY="50%"
android:duration="100"
android:repeatCount="4"
android:repeatMode="reverse" />



In Java code, create Animation of the anim resource file with AnimationUtils.loadAnimation() method, and start the animation with startAnimation() method of the target view.
package com.example.androidtextview;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
import android.app.Activity;

public class MainActivity extends Activity {

Animation myAnimation;
TextView myText;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myText = (TextView)findViewById(R.id.mytext);

myAnimation = AnimationUtils.loadAnimation(this, R.anim.myanimation);

myText.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View arg0) {
myText.startAnimation(myAnimation);
}});
}

}


    xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity" >

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:textStyle="bold|italic"
android:layout_gravity="center_horizontal" />

android:id="@+id/mytext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="http://picturedmagazine.blogspot.com/"
android:textStyle="bold"
android:textSize="30sp"
android:textColor="#0000ff" />





إرسال تعليق

0 تعليقات