0

I want move a bitmap in the screen, but i can do it only horizontally, because if I do it vertically, the scroll of the view start and the movement of the bitmap disappears. I have

public boolean onTouchEvent(MotionEvent event)

method where in case MOVE I change the X and Y of the bitmap. Then in onDraw() method I paint the bitmap. The scroll are in xml. Inside of it are a layout and inside a View.

I would like when I touch, in case DOWN, if I touch the bitmap, disable the scroll, but I is in other place no.

that is the resume of the code

public class Table extends ScrollView{

private static Integer srcX = 0, srcY = 0;

public Table(Context context) {
    super(context);
    setWillNotDraw(false);
    setVerticalScrollBarEnabled(true);

  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    for(int i=1; i<= Paint_Table.num_players; i++)
        canvas.drawBitmap(bitmap, X, Y, null);
  }

  @SuppressLint("ClickableViewAccessibility") @Override
  public boolean onTouchEvent(MotionEvent event) {

    int x = (int) event.getX();
    int y = (int) event.getY();

    switch(event.getAction()){

    case MotionEvent.ACTION_DOWN:
        if (youTouchBitmap) {
            srcX = x;
            srcY = y;
        }
        break;

    case MotionEvent.ACTION_MOVE:
        if (srcX !=0 && srcY != 0) {
           X=x;
           Y=y;
           invalidate();
        }
        break;
    }
    return true;
  }

}

Can someone help me? Thanks and regards.

javipipero
  • 89
  • 9

1 Answers1

0

since i dont see code ive find some link might help you: How to disable and enable the scrolling on android ScrollView?

in the link you can see in the answers a code that is custom scroll view its work on flag. you can choose when the scroll will work ot not. hope i helpd :)

Community
  • 1
  • 1
adids1221
  • 48
  • 1
  • 8
  • I put the resume od the code. I saw the solution, but i dont understand because in the green check code when _enableScrolling_ is true, not go out of the _onInterceptTouchEvent_ . Thanks again. – javipipero Apr 19 '15 at 22:39