ramsbh ramsbh - 1 year ago 100
Android Question

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"
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">

<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">



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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download