Android:浮动按钮图标未居中 [英] Android: Floating Button Icon is not centred

查看:89
本文介绍了Android:浮动按钮图标未居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用中创建一个浮动按钮.该按钮在那里,但是该按钮中的图像有点向上(参见图像).

I'm trying to create a floating button in my app. The button is there, but the image in the button is a bit upwards (see image).

我不知道这是怎么回事.以下是浮动按钮XML的一部分.

I can't figure out what's wrong with it. Below is part of the XML for floating button.

<android.support.design.widget.FloatingActionButton
        android:id="@+id/buttonUp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="16dp"
        android:layout_marginTop="480dp"
        android:clickable="true"
        android:scaleType="center"
        android:src="@drawable/btn_back_to_top_3x"
        app:layout_anchor="@id/layout"
        app:layout_anchorGravity="bottom|right|end"
        app:backgroundTint="@android:color/background_light"
        app:fabSize="normal" />

该按钮显示了我想要的位置.唯一的问题似乎是里面的图像不是中心.为什么会这样呢?

The button is showing where I wanted it. The only problem seems to be the image inside isn't center. Why is this happening?

编辑: 经过一番环顾四周后,我意识到图像本身存在问题,即图像实际上并未居中,并且底侧有空间(这会导致图像被向上推).

EDIT: After some more looking around I realized the image itself was having problem where the image isn't actually centered and there are space at the bottom side (which cause the image to being push upward).

推荐答案

原因是您的图片尺寸不合适!

Reason is your image is not in the right size!!

浮动操作按钮的默认圆圈大小为56 x 56dp , 为了获得最合适的效果,请使用它作为背景图片!

Floating action button default circle size is 56 x 56dp , to get the best fit use that for your background image!!

如果您要使用迷你相机,则应为:40 x 40dp

If you are going for a mini one should be : 40 x 40dp

如果您只想更改内部"图标(仅图标),请使用24 x 24dp图标作为默认大小

If you only want to change the Interior icon(only icon) use a 24 x 24dp icon for default size

要再次测试,我从互联网下载了一个图像表格并将其缩小到56dp,并保留了一个很小的空间来平衡它(我对Photoshop不好)

To test this again i download an image form internet and scaled it down to 56dp and kept a small space to balance it (i am no good with Photoshop)

并将其添加到您的FB视图中,并使背景变黄以使其清晰.让我们看看

and added this to your FB view and made background yellow to make it clear.Let's see

输出:

这意味着它取决于您添加的图像及其大小,如果要使用全背景,甚至可以使用imageButton

This means it depends on the image that you add and its size if you want to go full background you can even use an imageButton

参考: 查看全文

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