[android-developers] Re: strange behavior on rotating and scaling text
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) {
[android-developers] Re: strange behavior on rotating and scaling text
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