我正在一台安装了Android 6.0.1的设备上进行测试,问题在于我的FAB按钮只对layout_marginRight属性起作用,而无论我使用哪个值,它都不会对layout_marginBottom属性产生反应。
这是我的布局代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/scrollViewUnitNames"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_margin="16dp"
android:fillViewport="true"><!----></ScrollView>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="@dimen/fab_margin"
android:clickable="true"
android:id="@+id/fab"
android:src="@android:drawable/ic_dialog_email"
app:fabSize="normal"
app:borderWidth="0dp"
/> </RelativeLayout>
如果我将FAB对齐到左上角或右上角,那么margin有效。但是如果我将其对齐到左下角或右下角,layout_marginBottom似乎没有效果。我正在使用的是设计支持库23.2.0版本,在Android 4.0.3模拟器上测试过了。你有任何想法如何解决这个问题吗?谢谢!
编辑:这是它的外观:
![enter image description here](https://istack.dev59.com/NFoUx.webp)
RelativeLayout container = (RelativeLayout) findViewById(R.id.container);
container.removeAllViews();
container.addView(getLayoutInflater().inflate(R.layout.my_layout_file, null));
在一个新项目中,我做了同样的事情,在改变布局之前它是可以工作的,但在我改变之后,它看起来和上面的图片一样。这是更改布局的不正确方式吗?还是有更好的方法?感谢您的帮助。