1. Download our Official Android App: Forums for Android!

Apps Image with only certain parts to be clickable.

Discussion in 'Android Development' started by rchandler, Jun 2, 2011.

  1. rchandler

    rchandler Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Jun 2, 2011

    Jun 2, 2011
    4
    0
    5
    I am pretty new to building android apps and looking for some help.
    I am trying to get only certain parts of my image touchable. I think I am need to setup X Y coordinates but I am not sure how to do that or start it. Here is the code I have now to make the image touchable. So any help will be helpfull.

    import android.app.Activity;

    import android.os.Bundle;
    import android.view.View;
    import android.widget.ImageView;
    import android.view.MotionEvent;
    import android.view.View.OnTouchListener;

    public class PetMyPup extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);




    ImageView image = (ImageView) findViewById(R.id.image_View);
    image.setOnTouchListener(new OnTouchListener() {


    @Override
    public boolean onTouch(View v, MotionEvent event) {
    ImageView img = (ImageView) v;

    int action = event.getAction();
    if (action == MotionEvent.ACTION_DOWN){

    img.setImageResource(R.drawable.petmypupr);
    }

    else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL){
    img.setImageResource(R.drawable.petmypup);

    }

    return true;
    }
    });
    }
    }
     

    Advertisement

  2. Bob Cat

    Bob Cat Careful, They're sharp!!
    Rank:
    None
    Points:
    513
    Posts:
    7,046
    Joined:
    Nov 17, 2010

    Nov 17, 2010
    7,046
    4,288
    513
    Midland's, South Carolina
    Welcome to Android Forums! I am moving this to application development.
     

Share This Page

Loading...