RelativeLayout 的子视图占据整个屏幕

Child view of RelativeLayout takes the whole screen

大家好,我正在开发我已经完全完成的计算器应用程序,但我从一开始就面临一个问题,解决方案可能真的很简单,但我没有抓住它。我将用我编写​​的代码示例来解释我的问题。

<LinearLayout   xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"     android:orientation="vertical"  android:layout_height="match_parent"/>

<RelativeLayout

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:layout_weight="1"

    android:background="#FFA5E600"/>

        <TextView

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:text="Hello world"

            android:textSize="20sp"

            android:background="#FFFFFFFF"/>

</RelativeLayout>

This is the second part

<RelativeLayout

    android:layout_width="match_parent"
android:layout_height="wrap_content"

android:layout_weight="1"

android:background="#FF92CAFD"/>

<TextView

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:text="Hello world"

    android:textSize="20sp"/>

</RelativeLayout>

所以在这段代码中,我有 2 个高度为 wrap_content 的相对布局,它有一个布局权重属性 (1),这意味着当我设置高度时屏幕被分成 two.but第一个 RelativeLayout 中的任何子视图都覆盖了所有屏幕,所以我想用子视图填充第一个布局而不覆盖整个屏幕,如果可能的话我不想在第二个布局子视图中做任何更改。

我希望我说清楚了...抱歉英语不好

我想将屏幕分成两部分,但是当第一个布局中的任何子视图的高度设置为匹配专利时,第一个布局会覆盖第二个布局

所以有两件事,

1.you设置属性后关闭相对布局我的意思是, android:background="#FF92CAFD"/> 这一行应该像 android:background="#FF92CAFD"> 在两个相对布局中都没有 /,以便它具有像 Textview 这样的子视图。我认为它不像你的代码那样改变它。

2.in 相对布局将 layout_height 设置为 0dp,以便视图位于父布局内。不打扰别人的看法。

我希望您的代码在这些更改后能正常工作。