开发者

Android layout properties

What is the best way to hide layout on button press,i.e, hide a linear layout where main.xml contains many linear layouts or is it to be done by some other layout please let me know Below i have given an example of two linear layouts my question is 1.IS it correct 2on browse button press show linear layout2 ,hide linear layout1 and on send button press show linear layout1, hide linear layout2

Show me the relevant code to achieve this

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical" android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content">
 <Button android:text="Browse" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

</LinearLayout>
<LinearLayout android:id="@+id/linearLayout2" android:layout_width="wrap_content" android:layout_height="wrap_content"&开发者_运维技巧gt;

  <Button android:text="Send" android:id="@+id/send" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

</LinearLayout>


LinearLayout llToHide = (LinearLayout)findViewById(R.id.linearLayout1);
llToHide.setVisibility(View.INVISIBLE);

To show it again call:

llToHide.setVisibility(View.VISIBLE);

To make it as if it's not there call:

llToHide.setVisibility(View.GONE);

The xml attribute to make a View visible, invisible, or gone is:

android:visibility="visible"
android:visibility="invisible"
android:visibility="gone"

The difference between "invisible" and "gone" is that "invisible" will not be shown but the rest of the layout will stretch or move as if it is there. A view with a "gone" attribute will act as if it doesn't exist, but you can still change/manipulate it in case you want it seen eventually.


in your activity you need this code:

  findViewById(R.id.button1).setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
             LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout1);
             layout.setVisibility(View.GONE);
        }
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜