0

Sample UI which I am trying

In the attached image I am trying to achieve the alignment of a ui button, I have quite successfully done that but the issue is, its not quite reliable across different screen sizes. I did it with the help of attribute "android:layout_marginRight="60dp"" which is causing issue ("Login" button moves to the right) if I view it on big resolution screen.

And yes I have few more UI View below that login button, (which I have not included in image).

How to generically achieve this layout? UPDATED: XML layout schema

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dip"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dip"
            android:layout_marginTop="10dip"
            android:text="@string/login"
            android:textColor="@color/blue_txt"
            android:textSize="20sp"
            android:textStyle="bold" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dip"
            android:layout_weight="0.0"
            android:background="@drawable/rounded_edittext"
            android:ems="10"
            android:hint="Email or User name"
            android:typeface="serif" >

        </EditText>
    </LinearLayout>

    <EditText
        android:id="@+id/password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dip"
        android:background="@drawable/rounded_edittext"
        android:ems="10"
        android:hint="Password"
        android:inputType="textPassword"
        android:textStyle="normal"
        android:typeface="serif" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginRight="60dp"
            android:layout_marginTop="10dip"
            android:background="@drawable/loginpage_btn"
            android:text="@string/login_btn_text"
            android:textColor="@color/white" />
    </RelativeLayout>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="35dip"
        android:text="@string/login_no_account"
        android:textColor="@color/blue_txt"
        android:textSize="20sp"
        android:textStyle="bold"
        android:textStyle="bold" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dip"
        android:src="@drawable/login" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="10dip"
        android:background="@drawable/loginpage_btn"
        android:text="@string/login_signup"
        android:textColor="@color/white" />
</LinearLayout>
dcool
  • 4,039
  • 3
  • 16
  • 14

1 Answers1

-1

try this layout

updated

<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="10dp">
 <EditText android:layout_width="fill_parent" android:layout_height="wrap_content"
       android:id="@+id/edit1" />
 <EditText android:layout_width="fill_parent" android:layout_height="wrap_content"
       android:id="@+id/edit2" android:layout_below="@id/edit1" android:layout_marginTop="5dp"/>
 <Button android:layout_width="wrap_content" android:layout_height="wrap_content"
       android:id="@+id/button1" android:layout_below="@id/edit2" android:text="Login"
       android:layout_marginTop="5dp" android:layout_alignParentRight="true" android:layout_marginRight="60dp"/>

Pratik
  • 30,639
  • 18
  • 84
  • 159
  • 1
    you too are doing the same way as I am doing it android:layout_marginRight="60dp" it will not display the same on different resolution as marginRight="60dp" will be less/more for certain devices. – dcool Jan 05 '12 at 02:59