Here’s the XML code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text="Welcome"
android:layout_centerInParent="true" android:textSize="20sp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text="Welcome"
android:layout_centerInParent="true" android:textSize="20sp"/>
</RelativeLayout>
</RelativeLayout>
It’s not really the scene (The UI design is not that code, but I’m presenting it for simplification).
What I except from this code is that the TextViews will be displayed one by another relatively (in a vertical way). Like:
Welcome
Welcome
But instead the output is the following:
Welcome
Like, they’re nested together, stacked on each other.
I made the width layouts as fill parent, so why the other layout doesn’t go down? it overrides the first relativelayout.
I must have 2 layouts, so please don’t suggest me to create only one layout.
Thank you.
You need to set the relation of your layouts.
Try the modification I’ve made below.
I’ve given the top layout the
android:id="@+id/top_rel"to make it’s identification easier.Also I’ve told it to be laid out at the top of the view by using
android:layout_alignParentTop="true".The lower
RelativeLayoutthen is being laid out below the top one by usingandroid:layout_below="@id/top_rel".