I used TranslateAnimation and moved up and down in kind.
However, I understand, although after I shift the view and use View.GONE in its visibility, the view is still able to receive a touch event.
You can create the same problem by pressing the button so that the orange color view disappears at the bottom of the screen. Then, when you click on the bottom of the screen, you will realize that the touch event of the user view is still triggered.
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); int color = getResources().getColor(android.R.color.holo_orange_light); // construct the RelativeLayout final RelativeLayout customView = new RelativeLayout(this) { @Override public boolean onTouchEvent(MotionEvent event) { this.setPressed(true); Log.i("CHEOK", "OH NO! TOUCH!!!!"); return super.onTouchEvent(event); } }; customView.setBackgroundColor(color); final FrameLayout frameLayout = (FrameLayout)this.findViewById(R.id.frameLayout); frameLayout.addView(customView, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, 100, Gravity.BOTTOM)); customView.setVisibility(View.GONE); Button button = (Button)this.findViewById(R.id.button1); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (customView.getVisibility() != View.VISIBLE) { // Slide up! TranslateAnimation anim=new TranslateAnimation(0,0,100,0); anim.setFillAfter(true); anim.setDuration(200); Log.i("CHEOK", "VISIBLE!!!"); customView.setVisibility(View.VISIBLE); customView.setAnimation(anim); customView.setEnabled(true); } else { // Slide down! TranslateAnimation anim=new TranslateAnimation(0,0,0,100); anim.setFillAfter(true); anim.setDuration(200); // HELPME : Not sure why, after I hide the view by sliding it down, // making it View.GONE and setEnabled(false), it still able to // receive touch event. Log.i("CHEOK", "GONE!!!"); customView.setVisibility(View.GONE); customView.setAnimation(anim); customView.setEnabled(false); } } }); } }
The full source code to demonstrate this problem can be found here:
https://www.dropbox.com/s/1101dm885fn5hzq/animator_bug.zip
How can I make my custom view so as not to receive a touch event after I slide it down?
source share