最近项目中需要在右下角添加一个置顶按钮
部分布局如下
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_gray">
<ImageView
android:id="@+id/iv_totop"
android:layout_width="@dimen/x50"
android:layout_height="@dimen/y50"
android:layout_alignParentRight="true"
android:layout_marginRight="@dimen/x30"
android:layout_above="@+id/iv"
android:layout_marginBottom="@dimen/y30"
android:src="@drawable/to_top"
android:visibility="gone" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/iv"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
这个是最终版本 无效的版本就不展示了
最后总结:
RelativeLayout布局里 最下面的控件 android:layout_alignParentBottom="true"和 layout_marginBottom属性无效,如果添加一个其他控件使用layout_above让自己处于最下面的控件之上,那么layout_marginBottom属性有效。