Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with positioning textView under another textView in relative layout

Tags:

android

layout

I want to position my textview with numbers under the textview that contains text. I use this layout and the textviews overlap:

<?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 with this is:

enter image description here

like image 970
DixieFlatline Avatar asked Mar 17 '11 15:03

DixieFlatline


People also ask

What's the difference between LinearLayout and RelativeLayout?

LinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets.

How do you align at the bottom of relative layout?

If you have a relative layout that fills the whole screen you should be able to use android:layout_alignParentBottom to move the button to the bottom of the screen.

How do you right align in relative layout?

If you only want to align it to the right, just use android:layout_alignParentRight="true" . Then only use android:alignParentRight="true" and remove the alignParentLeft attribute.

Is Relative layout deprecated?

@filthy_wizard: RelativeLayout is not deprecated. PercentRelativeLayout is deprecated.


1 Answers

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

like image 122
Will Tate Avatar answered Nov 15 '22 10:11

Will Tate