1

I have the following Layout

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@+id/LinearLayout01"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:background="@drawable/flowerpower">

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_y="200dip"
            android:textColor="#000000"
            android:text="Test"/>
</AbsoluteLayout>

Now I have the problem that on different screen sized displays the TextView isnt in the right position beacause its an absolute Layout. How do I make this one work with a RelativeLayout? I suggest that this is the right solution? The RealtiveLayout?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
user758610
  • 49
  • 2
  • 3
  • 1
    could you define what the "right position" is? – jkhouw1 May 20 '11 at 09:52
  • thats the problem. i have a background that should fit to the text. the image has an extra small "windows" where the text view shoud be shown. its nessesry to define that absolute in a way that in every screen size the text and the backgorund are in the right positin. – user758610 May 20 '11 at 11:52

4 Answers4

1

First of all, Try not to use Absolute Layout as it is deprecated in android SDK.

Second for your code, try this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/LinearLayout01"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:background="@drawable/flowerpower">

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:textColor="#000000"
            android:text="Test"/>
</RelativeLayout>

This will align your textview to right of the screen. If you want to put a margin from right side of the screen, you can also use following code in your textview:

android:layout_marginRight="10dip"
mudit
  • 25,306
  • 32
  • 90
  • 132
  • sorry this doenst work - even with the margin right. the text never shows on the right side - its sticky to the left upper corner. i dont know y this is. – user758610 May 20 '11 at 11:49
  • ohh.. for the text on right add following code in your textview tag: android:gravity="right" – mudit May 20 '11 at 11:59
  • ok my fault sry. it worked. now is the dip value a relative value? because if not then the text view will be playced too much on the right if the screen is smaller. or is this handled by the Relative Layout intself. Thanks for your answers! – user758610 May 20 '11 at 12:37
0

For such a simple Layout you would use the LinearLayout. But you should check the Android Layout Documentation.

Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111
0

try this :

<RelativeLayout android:id="@+id/Layout01"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@drawable/flowerpower">

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:textColor="#000000"
        android:text="Hello world !!"/>
</RelativeLayout>

NB : follow this link

Houcine
  • 24,001
  • 13
  • 56
  • 83