当我使用layout_marginLeft或从代码设置左边距时,它可以作为layout_marginRight使用.当我在FrameLayout中放置View with layout_marginLeft或在 Android API上放置布局根目录时,会出现此行为. 11. ?xml version="
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:background="#77cc99"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:background="#eebbaa">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, MyActivity"
/>
</FrameLayout>
</FrameLayout>
默认情况下,对于FrameLayout,android:layout_gravity属性设置为“left”.如果你想使用android:layout_marginLeft你应该改变它:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginLeft="50dp"
android:background="#77cc99"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginLeft="50dp"
android:background="#eebbaa" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, MyActivity" />
</FrameLayout>
</FrameLayout>
