[英]Is this a bug in Android support design Library?
我刚刚开始使用来自Google的新Deisgn库:'com.android.support:design:22.2.0'
我使用FloatingActionButton,在Android 5.0以下和5.0以上之间存在一个小问题。 观看屏幕截图:
Android 4.4:
Android 5.0:
如您所见,在Android 4.4上,FAB周围有余量。 我认为这是为了显示阴影。 但是它太大了! 那么,这是一个错误(还是忘记了Google)还是仅仅是正常现象?
所托管的视图的xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="fr.freemo.freemo.activities.ListFreemoCityActivity">
<include
android:id="@+id/toolbar"
layout="@layout/view_toolbar" />
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar">
</FrameLayout>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="@dimen/margin_fab"
android:layout_marginRight="@dimen/margin_fab"
android:elevation="@dimen/fab_elevation_lollipop"
android:src="@drawable/ic_action_new"
app:backgroundTint="@color/color_app"
app:fab_type="normal" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_display"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/fab_add"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="@dimen/margin_fab"
android:layout_marginRight="@dimen/margin_fab"
android:elevation="@dimen/fab_elevation_lollipop"
android:src="@drawable/ic_map_white"
android:tint="@color/color_app"
app:backgroundTint="@color/white"
app:fab_type="normal" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_display_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/fab_display"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="@dimen/margin_fab"
android:layout_marginRight="@dimen/margin_fab"
android:elevation="@dimen/fab_elevation_lollipop"
android:src="@drawable/ic_action_list"
android:tint="@color/color_app"
android:visibility="invisible"
app:backgroundTint="@color/white"
app:fab_type="normal" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_display_grid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/fab_display_list"
android:layout_alignParentRight="true"
android:layout_marginBottom="@dimen/margin_fab"
android:layout_marginRight="@dimen/margin_fab"
android:elevation="@dimen/fab_elevation_lollipop"
android:src="@drawable/ic_view_module_white"
android:tint="@color/color_app"
android:visibility="invisible"
app:backgroundTint="@color/white"
app:fab_type="normal" />
</RelativeLayout>
这是一个问题(请检查我创建的错误报告: https : //code.google.com/p/android/issues/detail?id=175330 ),并且应该在支持设计库的将来版本中修复。
它是API 21的错误。您可以通过删除一些边距使箭头可见。 这是解决问题的方法,并且在不同设备上进行测试后似乎可以正常工作:
https://stackoverflow.com/a/31337162/3173384
已编辑
错误已得到修复。 只需将所有支持库更新到v 22.2.1
compile 'com.android.support:design:22.2.1'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:cardview-v7:22.2.1'
compile 'com.android.support:recyclerview-v7:22.2.1'
已经指定它不是实际的错误。 而是,这是预期的行为。
引用Google开发者答案:
从某种意义上说,这是绝对无法避免的,它不是错误,并且可以按预期工作。 在CoordinatorLayout中,我们可以进行一些控制,并且可以检测某些情况(边缘)可以抵消FAB的影响。 这是一个hack。
如果您不喜欢它,请将海拔高度设置为0dp并完成此操作。
正如其他人所说的,我们应该定义
xmlns:app="http://schemas.android.com/apk/res-auto"
app:borderWidth="0dp"
app:elevation="0dp"
或者甚至更好的是,根据要使用的API版本在dimens.xml中定义海拔高度。 最常见的情况是:
<!-- dimens.xml(v21) -->
<dimen name="custom_fab_elevation">@dimen/fab_elevation</dimen>
<!-- dimens.xml(lower) -->
<dimen name="custom_fab_elevation">0dp</dimen>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.