user758610
user758610

Reputation: 49

Relative Layout vs. Absolute Layout

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?

Upvotes: 1

Views: 4004

Answers (4)

Lukas Knuth
Lukas Knuth

Reputation: 25755

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

Upvotes: 0

Houcine
Houcine

Reputation: 24181

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

Upvotes: 0

mudit
mudit

Reputation: 25536

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"

Upvotes: 1

Related Questions