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

    "invisible" : 不可见

    "gone"      : 隐   藏

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

    test.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="100dip"
            android:layout_weight="1"
            android:background="@color/green" />
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="100dip"
            android:layout_weight="1"
            android:background="@color/red" />
    
    </LinearLayout>

    效果:

    invisible.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="100dip"
            android:layout_weight="1"
            android:background="@color/green" />
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="100dip"
            android:layout_weight="1"
            android:background="@color/red"
            android:visibility="invisible" />
    
    </LinearLayout>

    效果:

    gone.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="100dip"
            android:layout_weight="1"
            android:background="@color/green" />
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="100dip"
            android:layout_weight="1"
            android:background="@color/red"
            android:visibility="gone" />
    
    </LinearLayout>

    效果:

    从这三种效果,invisible和gone的区别就一目了然了。

  • 相关阅读:
    编译安装Nginx和php搭建KodExplorer网盘
    mysql二进制安装及基础操作
    Apache环境下搭建KodExplorer网盘
    编译安装Apache httpd和php搭建KodExplorer网盘
    KodExplorer介绍
    Nginx反向代理、负载均衡及日志
    Nginx include和Nginx指令的使用
    Nginx auto_index和auth_basic
    [译]在 64bit 环境中执行32 bit的SSIS包
    [译]SSIS 通过环境变量配置数据源连接参数
  • 原文地址:https://www.cnblogs.com/x-dev/p/3766047.html
Copyright © 2011-2022 走看看