ImageView selector
I have a view group that contains an image view. The view group is clickable and launches another activity. I want to set a selector for the im开发者_JS百科age view, so that it changes its source image when sele cted, but I don want the image view to intercept the click event. I want the view group to deal with the event. The image view should only change its drawable. Is that possible?
Thank you in advance,
Gratzi
If I understand you correctly, you could set a click listener onto the ImageView that doesn't do anything. That way the ImageView will intercept the click that normally the view group gets.
If you use a TouchListener
you can specify if the event is consumed or not. I use this code to press things within a GroupView
, but the GroupView
itself handles the OnClick
new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
lefter.setPressed(true);
contents.setPressed(true);
}
else if (event.getAction() == MotionEvent.ACTION_UP || !isInside(v, event)) {
lefter.setPressed(false);
contents.setPressed(false);
}
return false;
}
//...
}
The returned boolean is documented as follows: "True if the listener has consumed the event, false otherwise. "
精彩评论