Search code examples
androidmotion

Display layout on motion down and hide on motion up in android


I'm developing custom Media Controller and i have taken four button(play/pause,next,pre and bandwidth)inside a linear layout.I want when we touch screen then screen then this linear layout should visible for few second and after specified time this should invisible.I have done following code but its not working.

My code

@Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (mShowing) {
                        try {
                            linearl.setVisibility(View.GONE);

                        } catch (IllegalArgumentException ex) {
                            Log.w("MediaController", "already removed");
                        }
                        mShowing =!mShowing ;
                    }
                }
                return false;
            }
        });

So please suggest me how to do this


Solution

  • Try this...

      if (event.getAction() == MotionEvent.ACTION_UP) {
    
                             if(linearLayout.getVisibility() == View.GONE){
                                   linearLayout.setVisibility(View.VISIBLE);
                             }
                        }