【问题标题】:FAB from design library - wrong position来自设计库的 FAB - 位置错误
【发布时间】: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


【解决方案1】:

将 layout_alignParentBottom 和 layout_alignParentRight 设置为 true,如下例所示

<android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_gravity="bottom|end"
            android:layout_marginBottom="@dimen/fac_margin_bottom"
            android:layout_marginRight="@dimen/fab_margin_right"
            android:src="@mipmap/fab_add"
            app:backgroundTint="@color/fab_color"
            app:borderWidth="0dp"
            app:elevation="6dp"
            app:fabSize="normal"
            app:rippleColor="@android:color/white" />

【讨论】:

    猜你喜欢
    • 2016-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-25
    • 1970-01-01
    相关资源
    最近更新 更多