Note that there are some explanatory texts on larger screens.

plurals
  1. PO[Android]canvas.drawText is very slow while changing text size continuously
    text
    copied!<p>I'm trying to scale the text continuously by changing text size. And I implement my own view to drawText on canvas every time the text size changed. But the procedure of invalidate and redraw canvas became very slow which lead to some animation became slow too.</p> <p>The specific os version is 4.0.3(The application works well on the same kind device with os version 4.1.1)</p> <p>The hardware acceleration is on.(works well when it's off)</p> <p>I wrote a simple project to reproduce this issue. The custom view:</p> <pre><code>import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.util.AttributeSet; import android.view.View; public class MyTextView extends View { private Paint mPaint; private float mTextSize = 80f; public MyTextView(Context context) { this(context, null); } public MyTextView(Context context, AttributeSet attr) { super(context, attr); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setTextSize(mTextSize); } @Override public void onDraw(Canvas canvas) { canvas.save(); mPaint.setTextSize(mTextSize); canvas.drawText("Test test test", 200, 200, mPaint); canvas.restore(); mTextSize += 1f; } } </code></pre> <p>The Activity:</p> <pre><code>import android.os.Bundle; import android.view.MotionEvent; import android.app.Activity; public class MainActivity extends Activity { private MyTextView mTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTextView = (MyTextView)findViewById(R.id.text); } @Override public boolean onTouchEvent(MotionEvent event) { mTextView.invalidate(); return true; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload