Why does FAB appear different on different Android devices/OS versions?

依然范特西╮ 提交于 2019-12-10 23:31:50

问题


Can anyone tell me why exactly the same image (same image resource file as PNG, and same XML definition below) looks perfect on Android 5.1 and 7.1.1 (the image above) but bad on Android 4.1 (the image below).

The above image appears perfect on: Samsung real device 5.1 Pixel API 25 (7.1.1) emulator

The below image looks bad on: Samsung real device 4.3 Nexus One API 18 4.2 emulator

The XML code:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/myFAB"
    android:layout_width="75dp"
    android:layout_height="75dp"
    android:layout_gravity="center|bottom"
    android:layout_margin="@dimen/fab_margin"
    android:visibility="invisible"/>

Please advice how can I fix this problem.

EDIT: the images were generated from Android Studio "New Image Asset" and different resolutions (hdpi, mdpi, xhdpi, xxhdpi) has indeed been generated.


回答1:


FloatingActionButton cannot take any width/height. app:fabSize parameters specifies 3 sizes for the fab: auto, mini, and normal.

Leave layout_width and layout_height as wrap_content, and specify the desired fab size using app:fabSize="normal" (or other parameter from the list).



来源:https://stackoverflow.com/questions/44759018/why-does-fab-appear-different-on-different-android-devices-os-versions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!