android - FloatingActionButton 转义锚视图的边界
问题描述
我有这样的布局:
<CoordinatorLayout>
<NestedScrollView
android:id="@+id/contentScrollView
android:layout_width="600dp"
android:layout_Height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<ViewStub
android:id="@+id/viewStub"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</NestedScrollView>
<FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:layout_anchor="@id/contentScrollView"
app:layout_anchroGravity="bottom|right|end" />
</CoordinatorLayout>
现在,FAB 工作正常,但它逃脱了嵌套滚动视图的边界。它与底部边缘正确对齐,但它位于内容右边缘的中间(即 FAB 的一半在边界内,而另一半不在边界内)。
如果嵌套滚动视图的宽度设置为match_parent
,则它可以正常工作 - 这就是它在手机上的布局方式。但是,我希望滚动内容在平板电脑上具有恒定宽度,并且 FAB 应该在内容内部,而不是在内容之外。
如何将 FAB 设置在嵌套滚动视图的范围内?边距和填充似乎对水平对齐没有任何作用。
解决方案
尝试将android:layout_gravity
FloatingActionButton 设置为相反的值,即top|left|start
推荐阅读
- python-3.x - python模式验证问题
- batch-file - Start .exe with Batch file and several parameters
- css - 如何用圆角填充部分div?
- python - 致命的 Python 错误:init_sys_streams:无法初始化 sys 标准流 AttributeError:模块“io”没有属性“OpenWrapper”
- r - Shiny:从一个模块获取(反应式)值并将其(作为反应式)传递给另一个模块的 callModule() 函数
- excel - 从具有混合内容的 MS Excel 中的单元格中提取值
- ios - 使用“自动管理签名”/allowProvisioningUpdates 时何时更新配置文件?
- linux - 在 tcl exec 中传递变量参数的正确方法是什么?
- r - 将每一行与 data.frame 中的所有其他行进行比较
- sql - Oracle SQL 存储过程游标未循环或插入