简体   繁体   English

我的程序不会“ Repaint()”

[英]My program won't “Repaint()”

I'm coming in from Java, it won't "Repaint", by that I mean it won't move my bitmap to where someone clicks on the screen. 我来自Java,它不会“重绘”,这意味着它不会将我的位图移动到有人在屏幕上单击的位置。 There's nothing wrong with my code, logcat doesn't tell me nothing, the weird thing is it worked fine yesterday but now for some reason it won't work. 我的代码没有任何问题,logcat没有告诉我任何东西,奇怪的是,它昨天运行良好,但由于某种原因现在无法正常工作。

Activity.class 活动类

package com.example.alex.something;


    import android.app.Activity;
    import android.os.Bundle;

    public class Animation extends Activity {

private AnimationThread a;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    a = new AnimationThread(this);
    setContentView(a);
}

@Override
protected void onPause() {
    super.onPause();
    a.pause();
}

@Override
protected void onResume() {
    super.onResume();
    a.resume();
}
  }

AnimationThread.class AnimationThread.class

package com.example.alex.something;

  import android.content.Context;
  import android.view.*;

  import android.graphics.*;

   public class AnimationThread extends SurfaceView implements Runnable{

private Thread thread = null;
private SurfaceHolder holder;
private Boolean runnable = false;
private Bitmap ball;
private float x,y;

public AnimationThread(Context context) {
    super(context);
    ball = BitmapFactory.decodeResource(getResources(),R.drawable.redball);
    x=0; y=0;
    holder = getHolder();
}

@Override
public void run() {
    while(runnable==true){
        if(!holder.getSurface().isValid()){
            continue;
        }
        Canvas c = holder.lockCanvas();
        c.drawBitmap(ball,x-ball.getWidth()/2,y-ball.getHeight()/2,null);
        holder.unlockCanvasAndPost(c);
    }

}

public void pause(){
    runnable=false;
    while(true){
        try{
            thread.join();
        }
        catch(InterruptedException e){
            e.getStackTrace();

        }

    }

}

public void resume(){
    runnable=true;
    thread = new Thread(this);
    thread.start();

}


public MotionListener getListener(){MotionListener a = new MotionListener(); return a;}


private class MotionListener implements OnTouchListener{

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        x= event.getX();
        y= event.getY();
        return false;
    }
}

          }

Again as far as I know there's nothing wrong with my code, maybe someone more experienced might be able to see something, also is it possible something maybe wrong with my emulator, it worked fine yesterday? 再一次,据我所知,我的代码没有任何问题,也许更有经验的人可能看到了一些东西,也可能是我的模拟器有问题,它昨天工作正常吗?

It doesn't look like your set the touch listener. 看起来好像不是您设置的触摸侦听器。 You have an OnTouchListener class and a getter, but you never setOnTouchListener(listener) on a view. 您有一个OnTouchListener类和一个吸气剂,但从未在视图上设置setOnTouchListener(listener)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM