I have a menu imageview, when clicked on it my linearlayout(line2) appears, but it should again disappear on the next click of menu imageview
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
line1=(LinearLayout) findViewById(R.id.ll1);
line2=(LinearLayout)findViewById(R.id.ll2);
menu=(ImageView)findViewById(R.id.menu);
menu.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
menu.setVisibility(View.VISIBLE);
// TODO Auto-generated method stub
line1.setVisibility(View.VISIBLE);
line2.setVisibility(View.VISIBLE);
}
});
You can use an if/else statement to check the current state every time your button is pressed and switch. You don’t necessarily need to check for the visibility being GONE if you’re not going to set it to GONE ever so you can remove that condition.
The difference between GONE and INVISIBLE is that the layout reacts to gone as if it weren’t even there, the element no longer causes any displacement.
Change line2.setVisibility(View.VISIBLE); to