Android的设计库 - 浮动操作按钮填充/保证金的问题 [英] Android Design Library - Floating Action Button Padding/Margin Issues

查看:344
本文介绍了Android的设计库 - 浮动操作按钮填充/保证金的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是从谷歌设计库新FloatingActionButton,我得到一些奇怪的填充/保证金的问题。此图片(上开发布局选项)是由API 22。

I'm using the new FloatingActionButton from the Google Design Library and I am getting some strange padding/margin problems. This image (with developer layout options on) is from API 22.

和来自API 17。

这是XML

<android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_gravity="bottom|right"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="-32dp"
        android:src="@drawable/ic_action_add"
        app:fabSize="normal"
        app:elevation="4dp"
        app:borderWidth="0dp"
        android:layout_below="@+id/header"/>

为什么FAB在17 API要大得多填充/保证金明智?

Why is the FAB in API 17 so much larger padding/margin wise?

推荐答案

您可以轻松地使用API​​特定的风格做到这一点。在正常的值/ styles.xml ,把这样的事情:

You can accomplish this easily using API-specific styles. In your normal values/styles.xml, put something like this:

<style name="floating_action_button">
    <item name="android:layout_marginLeft">0dp</item>
    <item name="android:layout_marginTop">0dp</item>
    <item name="android:layout_marginRight">8dp</item>
    <item name="android:layout_marginBottom">0dp</item>
</style>

,然后在值-V21 / styles.xml,使用这样的:

and then under values-v21/styles.xml, use this:

<style name="floating_action_button">
    <item name="android:layout_margin">16dp</item>
</style>

和样式应用到您的FloatingActionButton:

and apply the style to your FloatingActionButton:

<android.support.design.widget.FloatingActionButton
...
style="@style/floating_action_button"
...
/>

正如其他人所指出的,在API小于20时,按钮呈现它自己的阴影,这增加了从整体上看逻辑宽度,而在API> = 20将使用新的高程参数,不参与该视图的宽度。

As others have noted, in API <20, the button renders its own shadow, which adds to the overall logical width of the view, whereas in API >=20 it uses the new Elevation parameters which don't contribute to the view width.

这篇关于Android的设计库 - 浮动操作按钮填充/保证金的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆