【问题标题】:Fab from support library not visible on Loliloop支持库中的 Fab 在 Loliloop 上不可见
【发布时间】:2015-10-06 15:12:39
【问题描述】:

我正在实施 Fab。它显示在设备 API 但它没有显示在 API >= 21 的设备上

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:background="@color/transparent"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?attr/actionBarSize"
        android:background="@color/background_chart"

        android:clickable="true">


        <ListView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:divider="@color/white_20"
            android:dividerHeight="1dip"
            android:footerDividersEnabled="false"
             />


    </RelativeLayout>

    <FrameLayout
        android:id="@+id/toolbar_shadow"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?attr/actionBarSize"
        android:background="@drawable/bottom_shadow"
        android:foreground="@drawable/bottom_shadow" />

     <android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_marginTop="@dimen/fab_margin_top"
    android:layout_marginRight="@dimen/fab_margin_right"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/ic_add"
    app:borderWidth="0dp"
    app:elevation="6dip"
    app:pressedTranslationZ="12dp" />
</RelativeLayout>

如何为所有 api >=15 显示它?

编辑: 问题似乎是由两个原因引起的。 1)在棒棒糖前app:pressedTranslationZ="12dp" 向下移动FAB(如边缘顶部,在棒棒糖中它不再作为边缘顶部工作,蝙蝠改变按下状态的高度。
2) 按钮放置在高度为 4(工具栏)的布局下,我尝试为 FAB 设置不同的 app:elevationandroid:elevation,但它没有任何改变。

【问题讨论】:

    标签: android android-design-library floating-action-button


    【解决方案1】:

    首先 API 20 是 Kitkat 4.4.2,而 21+ 是 Lollipop,23+ 是 Marshmallow

    在您的情况下,它可能隐藏在操作栏后面,请尝试检查更改...

    带有 FAB 的 Android 4.4 和 5.0 中的保证金问题 - Lollipop 存在保证金问题。要解决此问题,请将 API 21+ 的上边距和右边距都定义为 16dp,对于 pre-lollipop 都使用 0dp。

    值/dimens.xml

    <dimen name="fab_margin_right">0dp</dimen>
    <dimen name="fab_margin_top">0dp</dimen>
    

    values-v21/dimens.xml

    <dimen name="fab_margin_right">16dp</dimen>
    <dimen name="fab_margin_top">16dp</dimen>
    

    并在您的 FAB 内部布局中引用相同的值:

    <android.support.design.widget.FloatingActionButton
       ...
       ...
       android:layout_marginTop="@dimen/fab_margin_top"
       android:layout_marginRight="@dimen/fab_margin_right"/>
    

    参考:

    1. http://www.technotalkative.com/part-1-floating-action-button/
    2. http://antonioleiva.com/floating-action-button/

    【讨论】:

    • 它部分解决的问题,现在如果工具栏没有高程,FAB 是可见的,但是如果我将高程返回到工具栏,FAB 总是在它后面,尽管 fab 自己的高程。
    【解决方案2】:

    尝试将 xml 中的 FAB 移到 FrameLayout 之前,甚至在 RelativeLayout 之前。当我将 DrawerLayout 添加到我的 xml 文件时,我遇到了类似的问题。当我在 xml 文件中将 FAB 移到 DrawerLayout 之前时,FAB 出现了。

    【讨论】:

      【解决方案3】:

      增加海拔值。它可能位于另一个 UI 元素之后。

      在 Lollipop 及更高版本中,海拔控制元素将被绘制的“层”。

      【讨论】:

      • 如果工具栏没有标高,FAB 是可见的,但是如果我将标高返回到工具栏,FAB 总是在它后面,尽管 fab 自己的标高。
      猜你喜欢
      • 1970-01-01
      • 2015-08-14
      • 2017-04-27
      • 2012-06-30
      • 2015-11-15
      • 1970-01-01
      • 2018-03-18
      • 2015-12-14
      • 1970-01-01
      相关资源
      最近更新 更多