Hi I am a newbie in android. My question is is there any function to display an image from drawable into screen. By the way I am able to move the same image on the co-ordinates I touch, I just need the new image to be placed on the co-ordinate i touch.
Here's my code:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
private void placeImage(float X, float Y) {
ImageView flower = (ImageView) findViewById(R.id.img);
int touchX = (int) X;
int touchY = (int) Y;
flower.layout(touchX, touchY, touchX + 48, touchY + 48);
int viewWidth = flower.getWidth();
int viewHeight = flower.getHeight();
viewWidth = viewWidth / 2;
viewHeight = viewHeight / 2;
flower.layout(touchX - viewWidth, touchY - viewHeight, touchX + viewWidth, touchY + viewHeight);
}
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
int eventAction = event.getAction();
switch (eventAction) {
case MotionEvent.ACTION_DOWN:
float TouchX = event.getX();
float TouchY = event.getY();
placeImage(TouchX, TouchY);
break;
}
return true;
}