Android 浮动操作按钮布局_边距(底部)对底部边距没有影响
我在安卓6.0.1设备上进行测试,问题是我的FAB只对layout_marginRight做出反应,而不对layout_marginBottom做出反应,无论我使用的是哪个值 以下是我的布局:Android 浮动操作按钮布局_边距(底部)对底部边距没有影响,android,position,margin,android-relativelayout,floating-action-button,Android,Position,Margin,Android Relativelayout,Floating Action Button,我在安卓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="m
<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>
在一个新的项目中,我做了同样的事情,在我改变布局之前,它是有效的,在我改变布局之后,它看起来和上图一样。这是改变布局的错误方法吗?还是有更好的方法?感谢您的帮助。将
浮动操作按钮的xml更改为类似以下内容:
RelativeLayout container = (RelativeLayout) findViewById(R.id.container);
container.removeAllViews();
container.addView(getLayoutInflater().inflate(R.layout.my_layout_file, null));
<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_marginLeft="@dimen/fab_margin"
android:layout_marginTop="@dimen/fab_margin"
android:layout_marginRight="@dimen/fab_margin"
android:layout_marginBottom="50dp"
android:clickable="true"
android:id="@+id/fab"
android:src="@android:drawable/ic_dialog_email"
app:fabSize="normal"
app:borderWidth="0dp"
/>
到
它应该修正浮动操作按钮上的边距
将此视图添加到布局的底部
我不希望底部的边距与右侧的边距不同。我只是在测试它在不同的位置上是否有效,我发现只有底部保证金似乎不起作用。这就好像版面永远是零。你能发布一个你看到的屏幕截图吗?我复制粘贴了您的布局,并且下/右页边距都得到了尊重。将布局xml复制粘贴到测试项目中,并用线性布局填充滚动视图
,然后获得。我猜在您的布局或代码中还有一些没有包含在这里的东西导致了边距的变化。您是否在视图层次结构中的某个位置使用坐标布局
和app:layou behavior
呢?但是在scrollview中,我添加了一个垂直线性布局,在这个布局中,我添加了很多水平线性布局以及这个复选框和文本视图。非常感谢!但这是一种改变布局的好方法,对吗?我在运行sdk 23的Nexus 6模拟器上尝试过这种布局,它似乎工作得很好。是的,请阅读接受的答案。
container.addView(getLayoutInflater().inflate(R.layout.my_layout_file, null));
container.addView(getLayoutInflater().inflate(R.layout.my_layout_file, container, false));