嘗試重寫onTouch
方法,並在其中觸摸事件發生的座標添加圖像。
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN){
int x = (int) event.getX() ;
int y = (int) event.getY();
RelativeLayout.LayoutParams lp =new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);; //Assuming you use a RelativeLayout
ImageView iv=new ImageView(getApplicationContext());
lp.setMargins(x,y,0,0);
iv.setLayoutParams(lp);
iv.setImageDrawable(getResources().getDrawable(/*id of your image*/));
((ViewGroup)v).addView(iv);
}
,並確保佈局重寫onTouch的是RelativeLayout的,充滿整個屏幕
你也可以看看在Github以下的項目,它在一定程度上關係到你在找什麼。 enter link description here
非常感謝你 –