안드로이드 개발 질문/답변
(글 수 45,052)
package rakuseven.G1;
import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.os.Bundle; import android.util.AttributeSet; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.view.SurfaceHolder.Callback; import android.widget.ImageButton; import android.app.*; import android.content.*; import android.view.*; import android.view.View.*; import android.webkit.*; import android.widget.*;
public class RandomRun extends SurfaceView implements Callback { static Context mCtx; class RandomRun1 extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.title); Button button17 = (Button) findViewById(R.id.BTN_START); button17.setOnClickListener(this); //�ڷ� ��ư } }
@Override public void onClick(View v) { if (v.getId() == R.id.BTN_START) { Intent intent = new Intent(getApplicationContext(), G1.class); startActivity(intent); // TODO Auto-generated method stub }} RandomRun1 in = new RandomRun1();
}
public static void main(){ RandomRun local = new RandomRun(mCtx, null); }
class ImgThread extends Thread{ private Bitmap mImgBack; private int cnt = 0; private SurfaceHolder mSurfaceHolder; int xpos = 10; int ypos = 20; int BGmove = 0; int CENTER = 4; Horses horses;
public ImgThread(SurfaceHolder surfaceHolder, Context context){ mSurfaceHolder = surfaceHolder; Resources res = context.getResources(); mImgBack = BitmapFactory.decodeResource(res, R.drawable.bglong); horses = new Horses(context); }
public void run(){ for(int i = 0 ; i < 5; i++) horses.Horse[i].start(); while(true){ boolean changed = false; for(int i = 0 ; i < 5; i++){ if(horses.Horse[i].preStep != horses.Horse[i].LOCATION){ changed = true; } } Canvas canvas = null; if (changed) { try { canvas = mSurfaceHolder.lockCanvas(null); synchronized (mSurfaceHolder) { canvas.drawBitmap(mImgBack, BGmove, 0, null); cnt++; for (int i = 0; i < 5; i++) { if(horses.Horse[CENTER].LOCATION < 200){ xpos = horses.Horse[i].LOCATION; }else if(horses.Horse[CENTER].LOCATION >= 200 && horses.Horse[CENTER].LOCATION <= 1100){ xpos = 200 - (horses.Horse[CENTER].LOCATION -horses.Horse[i].LOCATION); BGmove = 200 - horses.Horse[CENTER].LOCATION; }else if(horses.Horse[CENTER].LOCATION > 1100){ xpos = horses.Horse[i].LOCATION - 900; } horses.Horse[i].mHImage[horses.Horse[i].FRAME % 2].setBounds(xpos, ypos + (i * 40),xpos + 100, ypos + (i * 40) + 100); horses.Horse[i].mHImage[horses.Horse[i].FRAME % 2].draw(canvas); } Paint paint = new Paint(); paint.setAntiAlias(true); paint.setTextSize(18); if(horses.NUMBER > 5){ canvas.drawText("- END -", 200, 100, paint); for(int i = 1; i <= 5; i++){ for(int j = 0; j < 5; j++){ if(i == horses.Horse[j].RANK){ canvas.drawText(i+"�� : "+horses.Horse[j].NAME, 170, 100+(i*22), paint); } } } break; } sleep(1); } } catch (InterruptedException e) { e.printStackTrace(); } finally { if (canvas != null) { mSurfaceHolder.unlockCanvasAndPost(canvas); } } } changed = false; } } }
private ImgThread thread; public RandomRun(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub mCtx = context; SurfaceHolder holder = getHolder(); holder.addCallback(this); thread = new ImgThread(holder, context); setFocusable(true); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub }
@Override public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub thread.start(); }
@Override public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub boolean retry = true; while(retry){ try{ thread.join(); retry = false; }catch(InterruptedException e){ } } } }
G1이 처음 시작화면이며, 내부 클래스를 써서
class RandomRun1 extends Activity implements OnClickListener
public class RandomRun extends SurfaceView implements Callback
둘 다 사용할수 있게는 만들었습니다.
버튼 터치는 작동하는데 G1으로 넘어가지는 않습니다..ㅠㅠ
꿈같은 답변 부탁드립니다!!