2016-08-22 91 views
1

我的佈局在Android 17上運行良好,但在Android 22上運行良好。長消息的右邊距應該爲50dp。layout_marginRight在RelativeLayout中適用於Android 17,但不適用於22

的Android 17:

enter image description here

的Android 22:

enter image description here

代碼:

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

回答

1

API你應該做的是利潤率的RelativeLayout不是TextView的

我希望這會幫助你。

+0

這適用於兩個版本。這會比在TextView上使用它有什麼缺點嗎? – Chris

+0

不,這不是缺點,但你的泡泡應該在RelativeLayout中,以便代碼放在那裏 –

0

用途: layout_marginEnd爲API以上21 和 layout_marginRight低於21

+0

已經嘗試過這個!根本不工作。 – Chris

+0

嘗試添加兩個相同的保證金值 –

+0

嗯,我做到了。不工作。 – Chris

0

請使用此代碼爲兩個API級的做工精細

<?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> 
相關問題