thx for the reply
how about the rotating? is it like scaling?

On Jun 22, 11:13 pm, Romain Guy <romain...@google.com> wrote:
> Hi,
> This is actually normal. Scaling fonts does not necessarily lead to a linear
> effect. Based on the font size, the text renderer can (and will) change the
> spacing, the antialiasing, etc. to improve on readability. If you want to
> scale text linearly you should turn the text into a bitmap first. If your
> animation is implemented using Views, you can simply enabled the drawing
> cache of the animated view.
>
>
>
> On Mon, Jun 22, 2009 at 8:46 AM, sleith <raysle...@gmail.com> wrote:
>
> > hi, i'm trying to animate text, but strange behavior happened when i
> > tried to rotate and scale.
> > When rotating, the text width becoming wider and narrower randomly
> > When scaling, the text y position is going upper.
> > i've test with image, but image works perfectly. don't know why text
> > is not.
> > Here's my code, please take a look or run it (only one file is enough
> > to run the demo)
> > thanks
>
> > public class TestDraw extends Activity {
> >        /** Called when the activity is first created. */
> >       �...@override
> >        public void onCreate(Bundle savedInstanceState) {
> >                super.onCreate(savedInstanceState);
>
> >                FrameLayout flContent = new FrameLayout(this);
> >                flContent.setLayoutParams(new
> > LayoutParams(LayoutParams.FILL_PARENT,
> >                                LayoutParams.FILL_PARENT));
> >                setContentView(flContent);
>
> >                SurfaceView svPreviewer = new SurfaceDrawer(this);
> >                svPreviewer.setLayoutParams(new LayoutParams
> > (LayoutParams.FILL_PARENT,
> >                                LayoutParams.FILL_PARENT));
>
> >                flContent.addView(svPreviewer);
> >        }
>
> >        private class SurfaceDrawer extends SurfaceView implements
> >                        SurfaceHolder.Callback, Runnable {
>
> >                private SurfaceHolder mSurfaceHolder;
> >                private int mLayoutWidth;
> >                private int mLayoutHeight;
>
> >                private String mText = "Hello World! Hello Android!";
> >                private Paint mFontPaint = new Paint();
> >                private Paint mBackgroundPaint = new Paint();
> >                private Rect mBackgroundRect = new Rect();
>
> >                // thread
> >                private Thread mThread;
> >                private boolean mIsStopped = false;
> >                private boolean mIsRunningMode = false;
> >                private Lock mLock = new ReentrantLock();
> >                private Condition mCond = mLock.newCondition();
>
> >                public SurfaceDrawer(Context context) {
> >                        super(context);
> >                        mSurfaceHolder = getHolder();
> >                        mSurfaceHolder.addCallback(this);
>
> >                        mFontPaint.setColor(Color.WHITE);
> >                        mBackgroundPaint.setColor(Color.MAGENTA);
>
> >                        // set the rect for background
> >                        mFontPaint.getTextBounds(mText, 0, mText.length(),
> > mBackgroundRect);
>
> >                        mThread = new Thread(this);
> >                        mThread.start();
> >                }
>
> >                public void surfaceChanged(SurfaceHolder holder, int format,
> > int
> > width,
> >                                int height) {
> >                        mLayoutWidth = width;
> >                        mLayoutHeight = height;
>
> >                        mLock.lock();
> >                        mIsRunningMode = true;
> >                        mCond.signal();
> >                        mLock.unlock();
> >                }
>
> >                public void surfaceCreated(SurfaceHolder holder) {
> >                }
>
> >                public void surfaceDestroyed(SurfaceHolder holder) {
> >                        mLock.lock();
> >                        mIsStopped = true;
> >                        mIsRunningMode = false;
> >                        mCond.signal();
> >                        mLock.unlock();
>
> >                        try {
> >                                mThread.join();
> >                        } catch (Exception e) {
>
> >                        }
> >                }
>
> >                public void run() {
> >                        while (mIsStopped == false) {
> >                                mLock.lock();
>
> >                                try {
> >                                        while (mIsRunningMode == false) {
> >                                                mCond.await();
> >                                        }
> >                                        if (mIsStopped == true) {
> >                                                mLock.unlock();
> >                                                break;
> >                                        }
>
> >                                        DrawRotationAnimation();
> >                                        DrawScalingAnimation();
>
> >                                } catch (InterruptedException e) {
> >                                        e.printStackTrace();
> >                                }
>
> >                                mLock.unlock();
> >                        }
> >                }
>
> >                public void DrawRotationAnimation() {
> >                        Canvas c;
> >                        int centerX = mLayoutWidth / 2;
> >                        int centerY = mLayoutHeight / 2;
> >                        for (int i = 0; i < 360; i += 20) {
> >                                c = mSurfaceHolder.lockCanvas();
> >                                c.save();
>
> >                                c.rotate(i, centerX, centerY);
> >                                c.translate(centerX -
> > (mBackgroundRect.width() / 2), centerY
> >                                                - (mBackgroundRect.height()
> > / 2));
>
> >                                c.drawColor(Color.BLACK);
> >                                c.drawRect(mBackgroundRect,
> > mBackgroundPaint);
> >                                c.drawText(mText, 0, 0, mFontPaint);
>
> >                                c.restore();
> >                                mSurfaceHolder.unlockCanvasAndPost(c);
> >                                SystemClock.sleep(300);
> >                        }
> >                }
>
> >                public void DrawScalingAnimation() {
> >                        Canvas c;
> >                        int centerX = mLayoutWidth / 2;
> >                        int centerY = mLayoutHeight / 2;
> >                        for (float scale = 1; scale < 3; scale += 0.2) {
> >                                c = mSurfaceHolder.lockCanvas();
> >                                c.save();
>
> >                                c.scale(scale, scale, centerX, centerY);
> >                                c.translate(centerX -
> > (mBackgroundRect.width() / 2), centerY
> >                                                - (mBackgroundRect.height()
> > / 2));
>
> >                                c.drawColor(Color.BLACK);
> >                                c.drawRect(mBackgroundRect,
> > mBackgroundPaint);
> >                                c.drawText(mText, 0, 0, mFontPaint);
>
> >                                c.restore();
> >                                mSurfaceHolder.unlockCanvasAndPost(c);
> >                                SystemClock.sleep(300);
> >                        }
> >                }
>
> >        }
> > }
>
> --
> Romain Guy
> Android framework engineer
> romain...@android.com
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support.  All such questions should be posted on public
> forums, where I and others can see and answer them
--~--~---------~--~----~------------~-------~--~----~
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-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to