I’m trying to move A picture in android, but I really don’t find A way to do it. I used already several methods but none of them really worked, this is my code at the moment
public class Tangram extends Activity implements OnTouchListener{
ImageView img;
int x=0,y=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.tangram);
img = (ImageView) findViewById(R.id.tangrampic1);
img.setOnTouchListener(this);
img.scrollBy(x, y);
}
public boolean onTouch(View v, MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
{
x++;
break;
}
case MotionEvent.ACTION_UP:
{
x--;
break;
}
}
return true;
}
}
Does anybody know how to move an object?
I would do it the following way:
– implement your own view
– in the ondraw method of this view paint your image ( starting with offset 0/0 )
– onTouch move the offset and invalidate the view