Chris
Chris

Reputation: 4368

layout_marginRight in RelativeLayout works on Android 17, but not on 22

My Layout works fine on Android 17, but not on Android 22. The long message should have a margin of 50dp to the right.

Android 17:

enter image description here

Android 22:

enter image description here

Code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="3dp"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="3dp"
                android:background="@drawable/bubble_new"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="10dp">

    <TextView
        android:id="@+id/list_message_item_username"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:ellipsize="end"
        android:textColor="#fff"
        android:textSize="17sp"
        android:textStyle="bold"/>

    <TextView
        android:id="@+id/list_message_item_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/list_message_item_username"
        android:layout_marginRight="50dp"
        android:ellipsize="end"
        android:textColor="#fff"
        android:textIsSelectable="true"
        android:textSize="17sp"/>
</RelativeLayout>

Upvotes: 1

Views: 103

Answers (3)

Riyaz Parasara
Riyaz Parasara

Reputation: 154

please use this code for both api level its working fine

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="3dp"
android:background="@drawable/bubble_new"
    android:layout_marginLeft="5dp"
    android:layout_alignParentStart="true"
    android:layout_marginTop="3dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="10dp"
    android:layout_alignParentLeft="true">

    <TextView
        android:id="@+id/list_message_item_username"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:ellipsize="end"
        android:textColor="#fff"
        android:textSize="17sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/list_message_item_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true"
        android:layout_marginEnd="50dp"
        android:layout_below="@id/list_message_item_username"
        android:layout_marginRight="50dp"
        android:ellipsize="end"
        android:textColor="#fff"
        android:textIsSelectable="true"
        android:textSize="17sp" />
</RelativeLayout>

Upvotes: 0

Pratik Panawala
Pratik Panawala

Reputation: 101

You should do that margin in RelativeLayout not in TextView

I hope this would be help you.

Upvotes: 1

Burhanuddin Rashid
Burhanuddin Rashid

Reputation: 5370

Use : layout_marginEnd for API above 21 and layout_marginRight for API below 21

Upvotes: 0

Related Questions