我正在开发狩猎游戏,因为我必须在水平方向移动枪,我可以展示枪,但是无法移动枪。对于我采取ontouchlistener
但无法移动的动作:
public class Touchmoveimage extends Activity {
int x,y,x1,y1;
RelativeLayout rl;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rl=(RelativeLayout)findViewById(R.id.bb);
x = getWindowManager().getDefaultDisplay().getWidth();
y = getWindowManager().getDefaultDisplay().getHeight();
final ImageView balls = (ImageView)findViewById(R.id.ball);
balls.setOnTouchListener(new View.OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
if(event.getAction()==MotionEvent.ACTION_DOWN)
{
x1=(int) event.getX();
y1=(int) event.getY();
RelativeLayout.LayoutParams param=new
RelativeLayout.LayoutParams(x1,y1);
rl.addView(balls, param);
}
return false;
}
}
);
}
}