Reputation: 36664
I have the following xml:
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.bla"
android:orientation="vertical"
android:id="@+id/root_layout"
android:layout_width="300dp"
android:layout_height="456dp"
android:layout_gravity="center"
android:background="@drawable/signup_popup"
android:padding="0dp">
...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:orientation="vertical"
>
<com.bla.view.text.blaTextView
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_weight="4"
android:layout_gravity="center_vertical"
android:background="@drawable/signup_bt_blue"
android:padding="0dp"
android:textColor="@color/solid_white"
android:textSize="18dp"
android:textStyle="italic"
android:text="Sign in"
android:gravity="center"
android:clickable="true"
android:id="@+id/account_details_continue"
android:ellipsize="end" android:singleLine="true"
/>
<com.bla.view.text.blaTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
style="@style/textSignUp"
android:textSize="16dp"
android:textStyle="italic"
android:textColor="#8fc0ce"
android:text="Already a blar?"
android:gravity="center_horizontal"
android:id="@+id/account_details_title3"
/>
</LinearLayout>
</RelativeLayout>
On high resolution devices (Nexus 4, 5) it shows the layout OK (see right figure in the attached image)
However when I deploy on low resolution devices (Nexus S, Sony Ericsson Xperia Arc S - LT18a.) it looks like the left figure in the attached image.
meaning +id/account_details_continue"
is aligned to its parent left.
I'm using only one layout.xml not for each screen resolution
I have tried to put much wider margin to the right, but yet it looks the same
<com.bla.view.text.blaTextView
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_marginLeft="42dp"
android:layout_marginRight="2dp"
android:layout_weight="4"
android:layout_gravity="center_vertical"
android:background="@drawable/signup_bt_blue"
android:padding="0dp"
android:textColor="@color/solid_white"
android:textSize="18dp"
android:textStyle="italic"
android:text="Sign in"
android:gravity="center"
android:clickable="true"
android:id="@+id/account_details_continue"
android:ellipsize="end" android:singleLine="true"
/>
How can i fix this?
Upvotes: 0
Views: 90
Reputation: 36664
Well it seems to be a bug on Android 2.3.3
Changing child's margins to Parent padding solved this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:layout_marginTop="20dp"
android:orientation="vertical"
>
<com.bla.view.text.blaTextView
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_weight="4"
android:layout_gravity="center_vertical"
android:background="@drawable/signup_bt_blue"
android:padding="0dp"
android:textColor="@color/solid_white"
android:textSize="18dp"
android:textStyle="italic"
android:text="Sign in"
android:gravity="center"
android:clickable="true"
android:id="@+id/account_details_continue"
android:ellipsize="end" android:singleLine="true"
/>
Upvotes: 1
Reputation: 1036
Try using the following to align your view:
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="52dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:text="TextView" />
Use it in relative layout. Notice that the width is wrap_content
Upvotes: 0