안드로이드 개발 질문/답변
(글 수 45,052)
쌩 초보인데요 ㅠ
화면내에서 폰의 각도의 좌표값에 맞춰서 이미지가 이동하도록 하는 앱을 구현하고 싶습니다.
현재 폰이 움직이는 좌표값 얻어오는 것 까지는 했는데요
이미지에 좌표값을 어떻게 넣어서 이미지 스스로 좌표값에 맞춰서 움지기이는지에 대한 개념이 안 잡히고 있습니다 ㅠ
이에 관한 간단한 예제같은거 어디 없을까요? ㅠ
주로 터치로 이미지 이동시키는 예제는 봤는데 얻은 좌표값에 맞춰서 이미지가 움직이게 하는 것에 대한건 없네요
응용하기도 좀 애메하구요. 고수님들의 답변 부탁드립니다 ㅠ
화면내에서 폰의 각도의 좌표값에 맞춰서 이미지가 이동하도록 하는 앱을 구현하고 싶습니다.
현재 폰이 움직이는 좌표값 얻어오는 것 까지는 했는데요
이미지에 좌표값을 어떻게 넣어서 이미지 스스로 좌표값에 맞춰서 움지기이는지에 대한 개념이 안 잡히고 있습니다 ㅠ
이에 관한 간단한 예제같은거 어디 없을까요? ㅠ
주로 터치로 이미지 이동시키는 예제는 봤는데 얻은 좌표값에 맞춰서 이미지가 움직이게 하는 것에 대한건 없네요
응용하기도 좀 애메하구요. 고수님들의 답변 부탁드립니다 ㅠ
2010.08.30 11:58:23
view에서 ondraw() 함수에서 canvas. 해서 그림 그리잖아요
그림 그릴때 x좌표 y좌표 넣어 주잖아요 그 좌표값을 public으로 해서 좌표 얻어오는 액티비티에서 그 좌표 값을 넣어준다음에
invalidate() 해주시면 될꺼에요
2010.08.30 13:06:04
답변 감사합니다 ㅎ 한가지 더 여쭐게요 ㅠ ㅎ
class SensorView extends View{
private static final int KUMA_SIZE = 50;
private Bitmap kuma;
private int w;
private int h;
private float x;
private float y;
public SensorView(Context context){
super(context);
requestWindowFeature(Window.FEATURE_NO_TITLE);
kuma = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon);
}
public void move(float mx, float my){
this.x -= (mx * 4f);
this.y += (my * 4f);
if(this.x < 0){
this.x = 0;
} else if((this.x + KUMA_SIZE)>this.w){
this.x = this.w - KUMA_SIZE;
}
if (this.y<0){
this.y = 0;
} else if((this.y + KUMA_SIZE)> this.h){
this.y = this.h - KUMA_SIZE;
}
invalidate();
}
protected void onSizeChanged(int w, int h, int oldw, int oldh){
this.w = w;
this.h = h;
this.x = (w - KUMA_SIZE)/2f;
this.y = (h - KUMA_SIZE)/2f;
}
@Override
protected void onDraw(Canvas canvas){
canvas.drawBitmap(kuma, x, y, null);
}
}
이런식으로 넣기는 했는데 ㅠ 액티비티 내에 class를 새로 만들어서 넣은거에요 ㅠ
class를 새로 넣는거 말고 액티비티에 바로는 못 넣나요?? ㅠ 제가 작업해둔 XML위에서 움직이도록 하고 싶은데 ㅠ
지금은 setContentView(sensorView);로 되어 있는데 setContentView(R.layout.main);으로 설정하면 sensorView를 어떤식으로 끌어와야 할까요 ? ㅠ
class SensorView extends View{
private static final int KUMA_SIZE = 50;
private Bitmap kuma;
private int w;
private int h;
private float x;
private float y;
public SensorView(Context context){
super(context);
requestWindowFeature(Window.FEATURE_NO_TITLE);
kuma = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon);
}
public void move(float mx, float my){
this.x -= (mx * 4f);
this.y += (my * 4f);
if(this.x < 0){
this.x = 0;
} else if((this.x + KUMA_SIZE)>this.w){
this.x = this.w - KUMA_SIZE;
}
if (this.y<0){
this.y = 0;
} else if((this.y + KUMA_SIZE)> this.h){
this.y = this.h - KUMA_SIZE;
}
invalidate();
}
protected void onSizeChanged(int w, int h, int oldw, int oldh){
this.w = w;
this.h = h;
this.x = (w - KUMA_SIZE)/2f;
this.y = (h - KUMA_SIZE)/2f;
}
@Override
protected void onDraw(Canvas canvas){
canvas.drawBitmap(kuma, x, y, null);
}
}
이런식으로 넣기는 했는데 ㅠ 액티비티 내에 class를 새로 만들어서 넣은거에요 ㅠ
class를 새로 넣는거 말고 액티비티에 바로는 못 넣나요?? ㅠ 제가 작업해둔 XML위에서 움직이도록 하고 싶은데 ㅠ
지금은 setContentView(sensorView);로 되어 있는데 setContentView(R.layout.main);으로 설정하면 sensorView를 어떤식으로 끌어와야 할까요 ? ㅠ



