gpt4 book ai didi

android - float 操作按钮 layout_margin(Bottom) 对底部边距没有影响

转载 作者:搜寻专家 更新时间:2023-11-01 08:37:01 25 4
gpt4 key购买 nike

我正在 Android 6.0.1 设备上进行测试,问题是无论我使用哪个值,我的 FAB 都只对 layout_marginRight 而不是 layout_marginBottom 使用react。

这是我的布局:

<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 对齐到左上角或右上角,则边距有效。如果我将它对齐到左下角或右下角,layout_marginBottom 似乎没有效果。我正在使用设计支持库 23.2.0。我在 Android 4.0.3 模拟器上对其进行了测试,它可以正常工作。你知道如何解决这个问题吗?谢谢!

编辑 这是它的样子: enter image description here

编辑 2我现在知道的更多一点:在创建时,我将内容 View 设置为空布局(内部只有一个相对布局)。经过一些测试后,我像这样更改布局:

RelativeLayout container = (RelativeLayout) findViewById(R.id.container);
container.removeAllViews();
container.addView(getLayoutInflater().inflate(R.layout.my_layout_file, null));

在一个新项目中,我做了同样的事情,在我改变布局之前它起作用了,在我改变它之后,它看起来和上图一样。这是更改布局的不正确方法吗?或者有更好的方法吗?感谢您的帮助。

最佳答案

FloatingActionButton 的 xml 更改为如下内容:

<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"
/>

如果您使用 android:layout_marginandroid:layout_marginBottom,它将覆盖您的底部边距。单独定义每个边距将使您的底部边距不同于顶部/左侧/右侧。

更新后的答案:

改变这一行:

container.addView(getLayoutInflater().inflate(R.layout.my_layout_file, null));

container.addView(getLayoutInflater().inflate(R.layout.my_layout_file, container, false));

它应该更正 FloatingActionButton 上的边距。

关于android - float 操作按钮 layout_margin(Bottom) 对底部边距没有影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35896433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com