"invisible" : 不可见
"gone" : 隐 藏
主要区别在于控件设置了invisible后控件不可见,但是保留了控件在界面上的空间,而设置为gone,则不保留控件占有的空间。
test.xml
01.
<?xml
version=
"1.0"
encoding=
"utf-8"
?>
03.
android:layout_width=
"match_parent"
04.
android:layout_height=
"match_parent"
05.
android:orientation=
"horizontal"
>
06.
07.
<TextView
08.
android:layout_width=
"match_parent"
09.
android:layout_height=
"100dip"
10.
android:layout_weight=
"1"
11.
android:background=
"@color/green"
/>
12.
13.
<TextView
14.
android:layout_width=
"match_parent"
15.
android:layout_height=
"100dip"
16.
android:layout_weight=
"1"
17.
android:background=
"@color/red"
/>
18.
19.
</LinearLayout>
效果:
invisible.xml
01.
<?xml
version=
"1.0"
encoding=
"utf-8"
?>
03.
android:layout_width=
"match_parent"
04.
android:layout_height=
"match_parent"
05.
android:orientation=
"horizontal"
>
06.
07.
<TextView
08.
android:layout_width=
"match_parent"
09.
android:layout_height=
"100dip"
10.
android:layout_weight=
"1"
11.
android:background=
"@color/green"
/>
12.
13.
<TextView
14.
android:layout_width=
"match_parent"
15.
android:layout_height=
"100dip"
16.
android:layout_weight=
"1"
17.
android:background=
"@color/red"
18.
android:visibility=
"invisible"
/>
19.
20.
</LinearLayout>
效果:
gone.xml
01.
<?xml
version=
"1.0"
encoding=
"utf-8"
?>
03.
android:layout_width=
"match_parent"
04.
android:layout_height=
"match_parent"
05.
android:orientation=
"horizontal"
>
06.
07.
<TextView
08.
android:layout_width=
"match_parent"
09.
android:layout_height=
"100dip"
10.
android:layout_weight=
"1"
11.
android:background=
"@color/green"
/>
12.
13.
<TextView
14.
android:layout_width=
"match_parent"
15.
android:layout_height=
"100dip"
16.
android:layout_weight=
"1"
17.
android:background=
"@color/red"
18.
android:visibility=
"gone"
/>
19.
20.
</LinearLayout>
效果:
从这三种效果,invisible和gone的区别就一目了然了。