Hide and show linearlayout Hide and show linearlayout android android

Hide and show linearlayout


LinearLayout one = (LinearLayout) findViewById(R.id.one);one.setVisibility(View.GONE);

I suggest that you use GONE insteady of INVISIBLE in the onclick event because with View.GONE the place for the layout will not be visible and the application will not appear to have unused space in it unlike the View.INVISIBLE that will leave the gap that is intended for the the layout


Add a boolean on your code

boolean flag = false;

then add android:clickable = true on your linear layout on xml

then use this code for reference

your_linear_layout = new OnClickListener(){    @Override    public void onClick(View v) {        if (flag){        // means true        your_linear_layout.setVisibility(View.INVISIBLE);        flag = false;         }        else{        your_linear_layout.setVisibility(View.VISIBLE)         flag = true;        }    }};   

Havent tried this yet but this should work..

Cheers


add setOnTouchListener to linearLayout get touch events as :

linearLayout.setOnTouchListener(new OnTouchListener(){  public boolean onTouch(View v, MotionEvent event){     if (event.getAction() == MotionEvent.ACTION_DOWN) {         // show-hide view here        return true;      }     if (event.getAction() == MotionEvent.ACTION_UP) {         // show-hide view here        return true;      }   return false;  }});

for making View visible use yourview.setVisibility(View.VISIBLE) and for Invisible use yourview.setVisibility(View.INVISIBLE)