需要处理drawableTop
的{{1}}点击事件,代码编写,
TextView
但是 tvSocialMedia.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_UP) {
if(event.getRawX() <= tvSocialMedia.getTotalPaddingTop()) {
// your action for drawable click event
tvEmail.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.email,0, 0);
tvPhone.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.phone,0, 0);
tvAddress.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.address,0, 0);
tvSocialMedia.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.social_media_select,0, 0);
usage.setText(getResources().getString(R.string.social_media));
return true;
}
}
return true;
}
});
内的代码没有被执行。如果我在if语句中写错了条件,请纠正我。
答案 0 :(得分:0)
更改处理drawableTop上的事件:
1)从
if(event.getAction() == MotionEvent.ACTION_UP)
到。{if(event.getAction() == MotionEvent.ACTION_DOWN)
2)从
if(event.getRawX() <= tvSocialMedia.getTotalPaddingTop())
到。{if(event.getRawY() >= tvPhone.getTop() - tvPhone.getTotalPaddingTop())
3)返回false
tvPhone.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN) {
if(event.getRawY() >= tvPhone.getTop() - tvPhone.getTotalPaddingTop()) {
// your action for drawable click event
tvEmail.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.email,0, 0);
tvPhone.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.phone_select,0, 0);
tvAddress.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.address,0, 0);
tvSocialMedia.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.social_media,0, 0);
usage.setText(getResources().getString(R.string.phone_no));
return true;
}
}
return false;
}
});