ramsbh
ramsbh

Reputation: 656

How to align view to right of the screen in Android?

How to align view to right of the screen in Android ? I have used this but not worked please help ?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/widget0"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#FFFFFF" android:paddingLeft="10px" android:paddingTop="10px"
    android:paddingBottom="10px" android:paddingRight="10px">

    <LinearLayout android:id="@+id/heading" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:orientation="horizontal">

        <ImageView android:id="@+id/widget30" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:src="@drawable/logo_cpw">
        </ImageView>

            <EditText android:id="@+id/widget28" android:layout_width="134px"
                android:layout_height="35px" android:text="EditText"
                android:textSize="18sp" android:background="@drawable/rounded_edit_text_effects"
                android:gravity="right" android:layout_alignParentRight="true" android:paddingRight="-10px">
            </EditText>

    </LinearLayout>

</RelativeLayout>

I have used absoluteLayout instead of relativelayout, but that too not worked. Please help ?

Upvotes: 2

Views: 18244

Answers (1)

mreichelt
mreichelt

Reputation: 12455

You can use the android:layout_gravity attribute on your views - android:gravity is just for the content.

But I really recommend using RelativeLayout because it usually fixes most of the problems right away. In fact you already have an attribute android:layout_alignParentRight="true" defined which is available only in a RelativeLayout.

Edit: Oh, and do not use px in any of your layouts - use density-independent pixels (dp) instead! You should really read the User Interface chapter from the documentation.

Upvotes: 18

Related Questions