Drawable不显示

时间:2011-10-20 09:03:42

标签: java android drawable

为什么mImage没有显示?

public class Manager extends Thread{
    private SurfaceHolder mSurfaceHolder;
    private boolean mRunning;



public Drawable mImage;
public Manager(SurfaceHolder surfaceHolder, Context context){

     mSurfaceHolder = surfaceHolder;
     mRunning = false;

     Resources res = context.getResources();


         mImage = res.getDrawable(R.drawable.nhero2);


  public void setRunning(boolean running)
   {
       mRunning = running;
   }

   public void run()
   {
       while (mRunning)
       {
           Canvas canvas = null;
           try
           {
               // подготовка Canvas-а
               canvas = mSurfaceHolder.lockCanvas();
               synchronized (mSurfaceHolder)
               {
                   // собственно рисование
                   //doDraw(canvas);
                   mImage.draw(canvas);
               }
           }
           catch (Exception e) { }
           finally
           {
               if (canvas != null)
               {
                   mSurfaceHolder.unlockCanvasAndPost(canvas);
               }
           }
       }
   }
}

P.S。对不起4我的英文

P.P.S。 我试图创造我自己的scrool射手哈 这里有完整的代码(sry for bad comments) 班级经理http://pastebin.com/Sjd57uqT class视图和类scrolBckgr http://pastebin.com/A5u5UJea

2 个答案:

答案 0 :(得分:1)

你需要调用mImage.setBounds(...);否则画布不知道在哪里绘制Drawable。

答案 1 :(得分:0)

我认为你遇到的主要问题是,只要用.start();启动线程,布尔mRunning就为假,线程会立即完成。当您尝试在线程启动后调用.setRunning(true);时,它将没有任何效果,因为线程已经完成。