Problems positioning textView under another textView in relative layout

I want to place a text image with numbers in a text form containing text. I use this layout and overlapping text views:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="@drawable/back" xmlns:android="http://schemas.android.com/apk/res/android"> <!-- we include header --> <include layout="@layout/header"/> <Spinner android:id="@+id/spinner" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="15dip" android:layout_marginLeft="5dip" android:layout_marginRight="5dip" android:textColor="#ffffff" android:background="@drawable/spin" /> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#000000"> <TextView android:id="@+id/tv1" android:text="Some text to display:" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_marginTop="10dip" android:textColor="#ffffff" /> <TextView android:id="@+id/number" android:text="123 456 789" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:textSize="30dip" android:layout_marginTop="10dip" android:textColor="#ffffcc"/> </RelativeLayout> </LinearLayout> 

What I get from this:

enter image description here

+4
source share
5 answers

you need android:layout_below="@id/tv1" in your TextView for numbers

+18
source

In the second TextView add

 android:layout_below="@id/tv1" 
+6
source

You are using a relative layout, but you are not specifying a second TextView, which should be positioned relatively. Add this to the second TextView:

 android:layout_below:"@id/tv1" 
+4
source

You should use LinearLayout, unless RelativeLayouts are designed to stack elements on top of each other by design, the following code creates a text view under a different text view;

 <LinearLayout android:id="@id/deal_time_details" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/deal_item_bg_red_gradient" android:baselineAligned="false" android:gravity="center_horizontal" android:orientation="vertical" android:paddingBottom="6.0dip" android:paddingLeft="10.0dip" android:paddingRight="12.0dip" android:paddingTop="6.0dip" > <TextView android:id="@id/name" style="@style/deal_item_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="@string/deal_details_time_ends" /> <TextView android:id="@id/company" style="@style/deal_item_number" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="-1.0dip" android:gravity="center_horizontal" android:gravity="center_vertical" android:text="@string/deal_details_time_redem" android:textSize="12.0dip" /> </LinearLayout> 
+1
source

Add

 android:layout_below="@id/tv1" 

In the XML representation of the view you want to place below.

0
source

Source: https://habr.com/ru/post/1344123/


All Articles