【发布时间】:2020-01-21 10:38:54
【问题描述】:
我有这样的布局:
<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 xml android-layout floating-action-button android-coordinatorlayout