I have controls that I want to focus on the center of the screen, so I used the following code
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical|center_horizontal" android:background="#DDDDDD"> <TextView android:id="@+id/tv_un" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="10pt" android:textColor="#444444" android:layout_marginRight="9dip" android:layout_marginTop="20dip" android:layout_marginLeft="10dip" android:text="User Name:"/> <EditText android:id="@+id/et_un" android:layout_width="150dip" android:layout_height="wrap_content" android:background="@android:drawable/editbox_background" android:layout_toRightOf="@id/tv_un" android:layout_alignTop="@id/tv_un"/> <TextView android:id="@+id/tv_pw" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="10pt" android:textColor="#444444" android:layout_below="@id/tv_un" android:layout_marginRight="9dip" android:layout_marginTop="15dip" android:layout_marginLeft="10dip" android:text="Password:"/> <EditText android:id="@+id/et_pw" android:layout_width="150dip" android:layout_height="wrap_content" android:background="@android:drawable/editbox_background" android:layout_toRightOf="@id/tv_pw" android:layout_alignTop="@id/tv_pw" android:layout_below="@id/et_un" android:layout_marginLeft="17dip" android:password="true" /> <Button android:id="@+id/btn_login" android:layout_width="100dip" android:layout_height="wrap_content" android:layout_below="@id/et_pw" android:layout_marginTop="15dip" android:layout_marginLeft="110dip" android:text="Login" /> <TextView android:id="@+id/tv_error" android:layout_width="fill_parent" android:layout_height="40dip" android:textSize="7pt" android:layout_below="@id/btn_login" android:layout_marginRight="9dip" android:layout_marginTop="15dip" android:layout_marginLeft="15dip" android:textColor="#AA0000" android:text=""/> </RelativeLayout>
but the result was the next image
any idea how to center them regardless of screen orientation
Best wishes
source share