MarginLeft不起作用:为什么?



>我有这个布局

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

我想知道为什么在某些手机或Android版本(主要是2.3姜饼)上,边距实际上为0,从某种意义上说,它没有与左边距分离,而是附加了,就好像没有android一样:layout_marginLeft="13dp"

尝试将android:layout_gravity="left"添加到文本视图中。layout_gravity的值可以是任何有效列表。

在您的 xml 中尝试以下操作。我添加了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"
            />

最新更新