0
我試圖啓動此代碼,以便打印行onTouch。該代碼不包含錯誤,但是當我啓動它時...模擬器意外關閉。你能幫我弄清楚這個問題嗎?意外的應用程序關閉
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
public class Usama3 extends Activity {
ImageView imageView;
Bitmap bitmap;
Canvas canvas;
Paint paint;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageView = (ImageView) this.findViewById(R.id.imageView11);
Display currentDisplay = getWindowManager().getDefaultDisplay();
float dw = currentDisplay.getWidth();
float dh = currentDisplay.getHeight();
bitmap = Bitmap.createBitmap((int)dw,(int)dh,Bitmap.Config.ARGB_8888);
canvas = new Canvas(bitmap);
paint = new Paint();
paint.setColor(Color.GREEN);
imageView.setImageBitmap(bitmap);
imageView.setOnTouchListener((OnTouchListener) this);
}
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
float upx;
float upy;
float downy = 0;
float downx = 0;
switch (action)
{
case MotionEvent.ACTION_MOVE:
upx = event.getX();
upy = event.getY();
canvas.drawLine(downx, downy, upx, upy, paint);
imageView.invalidate();
downx = upx;
downy = upy;
break;
}
return false;
}
}
我會真的很感謝
檢查logcat顯示的是什麼? – 2011-06-02 08:19:46
任何記錄信息? – 2011-06-02 08:20:00