vendredi 29 mai 2015

Click ImageView on Specific Location

I have an imageView and when I need to let the user click only on a specific location (the white space) as shown in the image below, any suggestion?

enter image description here

here is my xml

    <RelativeLayout
            android:id="@+id/lockRelativeLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginStart="5dp"
            >
            <ImageView
                android:id="@+id/imageView"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:background="@drawable/image" />
        </RelativeLayout>

and here is the code

    private View.OnTouchListener imageViewOnClickListener = new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int x = (int)event.getX();
            int y = (int)event.getY();
            if (event.getAction() == MotionEvent.ACTION_DOWN){
               //here i want if he clicked on specific location to go to another activity
 Intent intent = new Intent(context, ViewerActivity.class);
            context.startActivity(intent);
            }
            return true;
        }
    };

I don't know if i should use onClick or onTouchClick!!

Aucun commentaire:

Enregistrer un commentaire