如果在android中使用带有背景色的空布局,会发生什么?

如果在android中使用带有背景色的空布局,会发生什么?,android,android-layout,Android,Android Layout,布局的背景色将发生什么变化,如下所示: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="m

布局的背景色将发生什么变化,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@color/colorPrimary"
>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:text="Button"
    android:textSize="20sp"
    android:visibility="gone"
    android:textColor="@android:color/white"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"/>

案例1 如果
按钮的可见性设置为“不可见”,则
RelativeLayout的背景色会发生什么变化

案例2 如果
按钮的可见性设置为“已消失”,则
RelativeLayout的背景色会发生什么变化?

无。
因为您正在更改
版面的背景色,而不是按钮本身

它不会影响相对布局。按钮不可见后,按钮将消失,但仍会获得具有相同背景的相对布局。
有关更多参考信息,请访问此“希望此帮助”。

如果按钮可见性设置为“不可见”或“消失”,则RelativeLayout的背景色不会发生任何变化。您可以在更短的时间内亲自尝试。您可以尝试:我在一次采访中遇到了这个问题;采访者解释说,RelativeLayout的背景色不会显示,以防它没有孩子。谢谢大家。我已经试过了。但我想知道是否有我做错事的地方。非常感谢Pratik提供的链接。:)@帕万:没问题,快乐编码。:)