来自支持库的 Fab 在 Loliloop 上不可见
Fab from support library not visible on Loliloop
我正在实施 Fab。它显示在 API < 21 的设备上
但它不会在 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) 在 pre lollipop app:pressedTranslationZ="12dp"
中向下移动 FAB(就像 margin top,在 lollipop 中它不再作为 margin top,bat 改变了按下状态的高度。
2) 按钮放置在布局下,高度为 4(工具栏),我尝试为 FAB 设置不同的 app:elevation
和 android:elevation
,但它没有改变任何东西。
提高海拔值。它可能位于另一个 UI 元素后面。
在 Lollipop 及更高版本中,高度控制 "layer" 将绘制元素的高度。
首先 API 20 是 Kitkat 4.4.2,21+ 是 Lollipop,23+ 是 Marshmallow
在您的情况下,它可能隐藏在操作栏后面,请尝试检查更改...
FAB Android 4.4 和 5.0 中的边距问题 -
Lollipop 存在保证金问题。要解决此问题,请为 API 21+ 定义上边距和右边距均为 16dp,为 pre-lollipop 定义上边距和右边距均为 0dp。
values/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"/>
参考:
尝试将 FAB 移动到 FrameLayout 之前 xml 甚至 RelativeLayout 之前。当我将 DrawerLayout 添加到我的 xml 文件时,我遇到了类似的问题。当我在 xml 文件中将 FAB 移动到 DrawerLayout 之前时,FAB 出现了。
我正在实施 Fab。它显示在 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) 在 pre lollipop app:pressedTranslationZ="12dp"
中向下移动 FAB(就像 margin top,在 lollipop 中它不再作为 margin top,bat 改变了按下状态的高度。
2) 按钮放置在布局下,高度为 4(工具栏),我尝试为 FAB 设置不同的 app:elevation
和 android:elevation
,但它没有改变任何东西。
提高海拔值。它可能位于另一个 UI 元素后面。
在 Lollipop 及更高版本中,高度控制 "layer" 将绘制元素的高度。
首先 API 20 是 Kitkat 4.4.2,21+ 是 Lollipop,23+ 是 Marshmallow
在您的情况下,它可能隐藏在操作栏后面,请尝试检查更改...
FAB Android 4.4 和 5.0 中的边距问题 - Lollipop 存在保证金问题。要解决此问题,请为 API 21+ 定义上边距和右边距均为 16dp,为 pre-lollipop 定义上边距和右边距均为 0dp。
values/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"/>
参考:
尝试将 FAB 移动到 FrameLayout 之前 xml 甚至 RelativeLayout 之前。当我将 DrawerLayout 添加到我的 xml 文件时,我遇到了类似的问题。当我在 xml 文件中将 FAB 移动到 DrawerLayout 之前时,FAB 出现了。