在 FrameLayout 中使用 marginBottom
11 Jul 2014想把一个控件放到FrameLayout的底部位置,尝试了好久layout_marginBottom属性,居然毫无作用。但是layout_marginTop又是可以正确显示的。
现象如下:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:text="This text should be at bottom"
android:textSize="20dp" />
</FrameLayout>
显示如下图(错误):
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="This text should be at bottom"
android:textSize="20dp" />
</FrameLayout>
显示如下图(正确):
解决方案:
需要在做layout_marginBottom前设置layout_gravity为bottom
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="50dp"
android:text="This text should be at bottom"
android:textSize="20dp" />
</FrameLayout>
显示如下图(正确):