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;
}
});
}
}
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;
}
});
}
}