Home > other >  Child view of RelativeLayout takes the whole screen
Child view of RelativeLayout takes the whole screen

Time:03-27

Hello guys I am working on Calculator app which I have completely finished but there is only one problem I am facing from start and the solution might be really easy but I am not catching it. I will explain my problem with an example of code that I wrote.

<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>

So in this code I have 2 Relative layouts with height wrap_content and it has an attribute of layout weight (1) which mean that the screen is divided in two.but when i set the height of any child view in the first RelativeLayout it covers all the screen so I want to fill the fist layout with a child view without covering the full screen and if possible I dont want to do any changes in the seconds layout child views.

I hope i made it clear ... Sorry for bad English

I want to keep the screen in two parts but it the fist layout keep covering the second layout when the height of any child view in the first layout is set to match patent

CodePudding user response:

So there are 2 thing,

1.you closed the relative layout after setting the attributes i mean, android:background="#FF92CAFD"/> this line it should be end like android:background="#FF92CAFD"> without / in both Relative layout in order for it to have child views like Textview. I think its not like that in your code change it if it is.

2.in Relative layout set the layout_height to 0dp in order for the views to be inside the parent layout. without disturbing other views.

I hope your code works fine after these changes.

  • Related