zoukankan      html  css  js  c++  java
  • Android控件属性android:visibility的invisible与gone的区别

    "invisible" : 不可见

    "gone"      : 隐   藏

    主要区别在于控件设置了invisible后控件不可见,但是保留了控件在界面上的空间,而设置为gone,则不保留控件占有的空间。

    test.xml

    01.<?xml version="1.0" encoding="utf-8"?>
    02.<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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"?>
    02.<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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"?>
    02.<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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的区别就一目了然了。

  • 相关阅读:
    Windows编程系列:Windows中的消息
    python 日志 logging模块
    wx-xcx
    大坑:perspectiveTransform
    在移动硬盘上装系统
    Django
    双边滤波(Bilateral filter)
    Mesh Deformation with Laplacian Coordinates
    C++五十一篇 -- VS2017开发人员新闻无法联网
    idea 修改Git密码和账号后,Git提交账号的没有改变
  • 原文地址:https://www.cnblogs.com/wanghang/p/6299907.html
Copyright © 2011-2022 走看看