关于View的invisible和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="wrap_content"
    android:orientation="vertical"
    android:background="@color/entertainment_bg">
    <LinearLayout
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginBottom="9dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <RelativeLayout
                android:id="@+id/wonderful_act_layout1"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_marginRight="2.5dp"
                android:layout_height="96dp">
                <ImageView
                    android:id="@+id/room_img_1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop" />
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/char_bar_black_bg"
                    />
                <TextView
                    android:id="@+id/wonderful_act_online_num1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/entertainment_text_item_color"
                    android:layout_alignParentBottom="true"
                    android:layout_marginBottom="10dp"
                    android:layout_marginLeft="9dp"
                    android:textSize="11sp"
                    android:maxLines="1"
                    android:layout_marginRight="9dp"
                    android:text="1683人在线"/>

                <TextView
                    android:id="@+id/wonderful_act_name1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/entertainment_text_item_color"
                    android:textSize="14sp"
                    android:layout_alignParentBottom="true"
                    android:layout_marginBottom="25.5dp"
                    android:layout_marginLeft="9dp"
                    android:maxLines="1"
                    android:layout_marginRight="9dp"
                    android:text="抢福袋游戏"/>
                <View
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/sel_chat_bar_click"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentLeft="true" />

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/chat_bar_transparent_bg"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentLeft="true"
                    android:id="@+id/imageView5" />
            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/wonderful_act_layout2"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_marginLeft="2.5dp"
                android:layout_height="96dp">
                <ImageView
                    android:id="@+id/room_img_2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop"
                    />
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/char_bar_black_bg"
                    />
                <TextView
                    android:id="@+id/wonderful_act_online_num2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/entertainment_text_item_color"
                    android:layout_alignParentBottom="true"
                    android:layout_marginBottom="10dp"
                    android:layout_marginLeft="9dp"
                    android:maxLines="1"
                    android:layout_marginRight="9dp"
                    android:textSize="11sp"
                    android:text="1683人在线"/>

                <TextView
                    android:id="@+id/wonderful_act_name2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_above="@id/wonderful_act_online_num2"
                    android:textColor="@color/entertainment_text_item_color"
                    android:textSize="14sp"
                    android:layout_alignParentBottom="true"
                    android:layout_marginBottom="25.5dp"
                    android:layout_marginLeft="9dp"
                    android:maxLines="1"
                    android:layout_marginRight="9dp"
                    android:text="抢福袋游戏"/>
                <View
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/sel_chat_bar_click"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentLeft="true" />
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/chat_bar_transparent_bg"
                    />
            </RelativeLayout>

        </LinearLayout>
        <LinearLayout
            android:layout_marginTop="5dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <RelativeLayout
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="96dp"
                android:layout_marginRight="2.5dp"
                android:id="@+id/wonderful_act_layout3">
                <ImageView
                    android:id="@+id/room_img_3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentLeft="true" />
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/char_bar_black_bg"
                    />
                <TextView
                    android:id="@+id/wonderful_act_online_num3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/entertainment_text_item_color"
                    android:layout_alignParentBottom="true"
                    android:layout_marginBottom="10dp"
                    android:layout_marginLeft="9dp"
                    android:maxLines="1"
                    android:layout_marginRight="9dp"
                    android:textSize="11sp"
                    android:text="1683人在线"/>

                <TextView
                    android:id="@+id/wonderful_act_name3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/entertainment_text_item_color"
                    android:textSize="14sp"
                    android:layout_alignParentBottom="true"
                    android:layout_marginBottom="25.5dp"
                    android:layout_marginLeft="9dp"
                    android:maxLines="1"
                    android:layout_marginRight="9dp"
                    android:text="抢福袋游戏"/>
                <View
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/sel_chat_bar_click"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentLeft="true" />

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/chat_bar_transparent_bg"
                    />
            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/wonderful_act_layout4"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_marginLeft="2.5dp"
                android:layout_height="96dp">
                <ImageView
                    android:scaleType="centerCrop"
                    android:id="@+id/room_img_4"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    />
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/char_bar_black_bg"
                    />
                <TextView
                    android:id="@+id/wonderful_act_online_num4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/entertainment_text_item_color"
                    android:layout_alignParentBottom="true"
                    android:layout_marginBottom="10dp"
                    android:layout_marginLeft="9dp"
                    android:maxLines="1"
                    android:layout_marginRight="9dp"
                    android:textSize="11sp"
                    android:text="1683人在线"/>

                <TextView
                    android:id="@+id/wonderful_act_name4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/entertainment_text_item_color"
                    android:textSize="14sp"
                    android:layout_alignParentBottom="true"
                    android:layout_marginBottom="25.5dp"
                    android:layout_marginLeft="9dp"
                    android:maxLines="1"
                    android:layout_marginRight="9dp"
                    android:text="抢福袋游戏"/>
                <View
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/sel_chat_bar_click"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentLeft="true" />
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/chat_bar_transparent_bg"
                    />
            </RelativeLayout>

        </LinearLayout>


    </LinearLayout>

</LinearLayout>

效果图


其实就是4个布局,上下等高,左右均分宽度。但是服务器,一次给我们吐得数据不确定,我们接受到的数据不确定,所以要根据数据的个数确定房间的个数信息,当时比如有3个数据的时候,房间1,2,3我都可以填满。但是4没有数据。我设置为View.Gone,此时房间3就充满了整个第二行的宽度。以前没有注意这些细节性的问题,也从来没有纠结过。这次知道坑了,View.invisible其实是可以占据你所设定的外层布局的位置的。二由于房间3和房间4是weight都为1的,所以设置房间4为View.GONE的时候,房间3就冲满整个第三行的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值