【发布时间】:2015-12-26 06:05:08
【问题描述】:
最近我一直在尝试使用 Google 的新设计库,但 FAB View 并没有像我预期的那样工作。
这是我的布局的样子(我在 CoordinatorLayout 中删除了这些布局的子级以使其更清晰)
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/action_clear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:selectableItemBackground"
android:minHeight="@dimen/material_54"/>
<RelativeLayout
android:id="@+id/action_rewrite"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:selectableItemBackground"
android:minHeight="@dimen/material_54"/>
<include layout="@layout/shadow_down" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/window_background"/>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/action_import"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:src="@drawable/log_cell_changed"
android:layout_marginRight="@dimen/space_16"
android:layout_marginBottom="@dimen/space_16"
app:borderWidth="0dp"
app:elevation="4dp"
app:fabSize="normal" />
</android.support.design.widget.CoordinatorLayout>
问题是当我运行应用程序时屏幕上不存在 FAB。然而,Android Studio 上的“预览”正确显示了它。 我试着玩了一下,当我添加
android:layout_marginBottom="110dp"
对于 FAB,它将导致 FAB 将出现在它应该放置的位置,而没有额外的边距。
【问题讨论】:
-
你正在使用的设计库的女巫版本?我用您的代码创建了一个示例项目,一切正常。我正在使用
com.android.support:design:23.0.1 -
我也在使用 23.0.1 (Android 6.0, Nexus 5, Developer preview 3)
标签: android android-design-library floating-action-button