Tuesday, January 3, 2012

Re: [android-developers] need help on text rotation

package com.anim.AnimationSample;

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 AnimationSample extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(new GraphicsView(this));
        }
        private static class GraphicsView extends View {
                private static final String AnimatedTxt =
                        "This Sample Program Shows, Aniamtion Using Path. This is very simple and easy to understand.";

                private Animation rotateAnim;

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

                        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);
                }
        }
}


On Wed, Jan 4, 2012 at 11:02 AM, chowdary nani <naveenneelinfo@gmail.com> wrote:
Hi All,
I need help on rotating the text to certain angle on key code events in android
will please help me any one.






--
WITH REGARDS
ARUN KUMAR P D
+91-9663471079

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment