Amazing Tutorials for Android Developers...

Friday, May 17, 2013

Animated Text Tutorial

Text animation tutorial. text animation in round shape if you need to change shape little-bit changes required.


MainActivity.java

package com.example.animae.text;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Path.Direction;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;

public class MainActivity extends Activity {

 int colorAlpha=getTitleColor();;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new GraphicsView(this));
    }
    private static class GraphicsView extends View {
        private static final String AnimatedTxt =
            "devloped by Sandip Chaniyara (Sandy)";

        private Animation rotateAnim;

        public GraphicsView(Context context) {
            super(context);
        }
        private void createAnim(Canvas canvas) {
            rotateAnim = new RotateAnimation(0, 90, canvas.getWidth()/2, canvas.getHeight()/2);
            rotateAnim.setRepeatMode(Animation.REVERSE);
            rotateAnim.setRepeatCount(Animation.INFINITE);
            rotateAnim.setDuration(10000L);
            rotateAnim.setInterpolator(new AccelerateDecelerateInterpolator());

            startAnimation(rotateAnim);
        }
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);

            // creates the animation the first time
            if (rotateAnim == null) {
                createAnim(canvas);
            }

            Path circle = new Path();

            int centerX = canvas.getWidth() / 2;
            int centerY = canvas.getHeight() / 2;
            int r = Math.min(centerX, centerY);

            circle.addCircle(centerX, centerY, r, Direction.CW);
            Paint paint = new Paint();
            paint.setColor(Color.GREEN);
            paint.setTextSize(30);
            paint.setAntiAlias(true);

            canvas.drawTextOnPath(AnimatedTxt, circle, 0, 30, paint);
        }
    }
}
 
activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"
        android:marqueeRepeatLimit="marquee_forever"
        tools:context=".MainActivity" />
</RelativeLayout>


No comments:

Post a Comment

Animation Tutorial

Animation Image Used in Android Tutorial GIF Image used in Android Application. for that you need to use following code implementation...