title: Android: custom view is too slow?
body: <p>I have a custom view with a lot of png images on it(For every three characters an image). but it is too slow on drawing and scrolling.</p>
  
  <p>It is my code for custom view:</p>
  
  <pre><code>public class Textview extends View
  {       
      private String m_szText;
      Context ctx;
      Paint mTextPaint;
      private Canvas canva;
      Bitmap b ;
  
      public Textview(Context context)
      {
          super(context);
          ctx = context;          
          mTextPaint= new Paint();            
          mTextPaint.setTypeface(m_tTypeface);
          mTextPaint.setStyle(Paint.Style.FILL);
      }           
  
      public void SetText(String newtext) {
          m_szText = newtext;
          text(newtext);
          this.invalidate();
      }
      @Override 
      protected void onDraw(Canvas canvas)
      {               
          super.onDraw(text(canvas,m_szText));
      }
  
      Canvas text(Canvas canvas,String txt)
      {        
          int left = 400;         
          int top = 0;        
          try {
              for(int i=0;i&lt;txt.length();i=i+3)
              {
                  String adres = "glyph/" + txt.substring(i, i+3) + ".png";               
                  Bitmap btm = getBitmapFromAsset(adres);
                  if(left &lt;= 5) 
                      {left = 400;top += btm.getHeight();}
                  else
                      left = left - btm.getWidth();
                  canvas.drawBitmap(btm, left ,top,mTextPaint);
              }
          } catch (IOException e) {
              canvas.drawText(e.toString(), 50, 50, mTextPaint);
          }
          return canvas;
      }
  
      private Bitmap getBitmapFromAsset(String strName) throws IOException
      {
          AssetManager assetManager =  ctx.getAssets();
          InputStream istr = assetManager.open(strName);        
          Bitmap bitmap = BitmapFactory.decodeStream(istr);
          return bitmap;
      }
  
  }
  </code></pre>
  
  <p>How can I speed up my custom view? I think I must to create bitmap of all images once. but how to?</p>
  
  <p>thanks in advance!</p>