简体   繁体   中英

MarginLeft doesn't work: Why?

i have this layout

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

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <TextView
        android:id="@+id/textView2"
        android:layout_marginLeft="13dp"
        android:layout_marginRight="0dp"
        android:layout_marginBottom="0dp"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:textSize="16sp"
        android:text="@string/text"
        />
</ScrollView>
</RelativeLayout>

I would like to know why on some phones or versions of Android (2.3 Gingerbread mainly) the margins are pratically 0, in the sense that it is not detached from the left margin but it is attached, as if there were no android:layout_marginLeft="13dp"

Try to add android:layout_gravity="left" to your textView. Value of layout_gravity can be any of valid list.

Try the following in your xml .I have added android:layout_gravity="left"

  <TextView
            android:id="@+id/textView2"
            android:layout_marginLeft="13dp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
             android:layout_gravity="left"
            android:textSize="16sp"
            android:text="text"
            />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM