**Problem**

I'm looking to create the effect where a initial press of a button sets the visibility of 3 other buttons from gone to visible. After swiping towards and ending on one of the newly visible buttons I want to kick off a different activity.

My problem is that regardless of method I use to get the position of the views (using Rect objects, findNearestTouchable) and the position touch event (using onTouch/Gestures with ACTION\_UP) they never seem to match up and i'm never able to return the view I want;

**Desired Functionality**

A motion event which starts from the press of a button and ends on another button, to return the id/view object of the button it ends on.

My main\_menu.xml

```
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Button"        
        android:tag="1"

        />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button1"
        android:layout_marginBottom="36dp"
        android:layout_marginRight="19dp"
        android:layout_toLeftOf="@+id/button1"
        android:text="Button"
        android:visibility="gone"
        android:tag="3" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button3"
        android:layout_alignBottom="@+id/button3"
        android:layout_toRightOf="@+id/button3"
        android:text="Button"
        android:visibility="gone" 
        android:tag="2"/>

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button3"
        android:layout_alignBottom="@+id/button3"
        android:layout_alignParentRight="true"
        android:layout_marginRight="20dp"
        android:text="Button"
        android:visibility="gone"
        android:tag="4" />

</RelativeLayout>

```

Current attempt at Activity, which doesn't set  `foundit` (I am very open to completely different implementations)

```
public class Menu extends Activity {
    private GestureDetector gestureDetector;
    View.OnTouchListener gestureListener;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_menu);

        gestureDetector = new GestureDetector(new MyGestureDetector());
        gestureListener = new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                View findViewById2 = findViewById(R.id.button2);
                View findViewById3 = findViewById(R.id.button3);
                View findViewById4 = findViewById(R.id.button4);
                findViewById2.setVisibility(View.VISIBLE);
                findViewById3.setVisibility(View.VISIBLE);
                findViewById4.setVisibility(View.VISIBLE);
                return gestureDetector.onTouchEvent(event);
            }
        };
        View button = findViewById(R.id.button1);
        button.setOnTouchListener(gestureListener);

    }

    class MyGestureDetector extends SimpleOnGestureListener {
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                float velocityY) {

            View foundit = null;
            ViewGroup menu = (ViewGroup) findViewById(R.id.button1).getParent();
            for (int numChildren = menu.getChildCount(); numChildren >= 0; --numChildren) {
                View child = menu.getChildAt(numChildren - 1);
                if (child instanceof Button) {
                    Rect bounds = new Rect();
                    child.getHitRect(bounds);
                    if (bounds.contains((int) e2.getX(), (int) e2.getY())) {
                        foundit = child;
                    }
                }
            }
            if (foundit != null) {
                Log.i("found", "FOUND IT");
            }
            return false;
        }

        @Override
        public boolean onDown(MotionEvent e) {
            return true;
        }
    }

}

```

Does anyone have any insight?

**Edit**:

testing the following: 

```
    gestureListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            View findViewById2 = findViewById(R.id.button2);
            View findViewById3 = findViewById(R.id.button3);
            View findViewById4 = findViewById(R.id.button4);
            findViewById2.setVisibility(View.VISIBLE);
            findViewById3.setVisibility(View.VISIBLE);
            findViewById4.setVisibility(View.VISIBLE);
            if (event.getAction() == MotionEvent.ACTION_UP) {
                Log.i("TOUCH X IS", Float.toString(event.getRawX()));
                Log.i("TOUCH Y IS", Float.toString(event.getRawY()));
            }
            for (int numChildren = ((ViewGroup) v.getParent())
                    .getChildCount(); numChildren >= 0; --numChildren) {
                View child = ((ViewGroup) v.getParent())
                        .getChildAt(numChildren - 1);
                if (child instanceof Button) {
                    Rect bounds = new Rect();
                    child.getHitRect(bounds);
                    Log.i(child.getTag().toString() + " CENTER X IS",
                            Float.toString(bounds.exactCenterX()));
                    Log.i(child.getTag().toString() + " CENTER Y IS",
                            Float.toString(bounds.exactCenterY()));
                }
            }
            return false;
        }
    };

```

yields the following LogCat output:

`07-06 01:12:58.245: TOUCH X IS(20965): 394.0`

07-06 01:12:58.245: TOUCH Y IS(20965): 297.0

07-06 01:12:58.245: 4 CENTER X IS(20965): 392.0

07-06 01:12:58.245: 4 CENTER Y IS(20965): 219.0

07-06 01:12:58.245: 2 CENTER X IS(20965): 240.0

07-06 01:12:58.250: 2 CENTER Y IS(20965): 219.0

07-06 01:12:58.250: 3 CENTER X IS(20965): 95.0

07-06 01:12:58.250: 3 CENTER Y IS(20965): 219.0

07-06 01:12:58.250: 1 CENTER X IS(20965): 240.0

07-06 01:12:58.250: 1 CENTER Y IS(20965): 345.0