如何设置“浮动操作按钮"图像以填充按钮? [英] How to set Floating Action Button image to fill the button?
本文介绍了如何设置“浮动操作按钮"图像以填充按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通常为浮动操作按钮设置图标,但是我需要设置图像,以便制作圆形图像.
Usually icons are set for floating action buttons, but I need to set an image, so I can make a circular image.
我将其添加到项目中(使用Android Studio->新建"->图像资产"),但是图像并未填充整个按钮:
I added it to the project (using Android Studio-> New -> Image Asset), but the image didn't fill the entire button:
我的xml:
<com.github.clans.fab.FloatingActionMenu
android:id="@+id/run_menu"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:paddingBottom="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:visibility="visible"
fab:fab_colorNormal="#DA4336"
fab:fab_colorPressed="#E75043"
fab:fab_colorRipple="#99FFFFFF"
fab:fab_shadowColor="#66000000"
fab:fab_showShadow="true"
fab:layout_constraintBottom_toBottomOf="parent"
fab:layout_constraintHorizontal_bias="0.0"
fab:layout_constraintLeft_toLeftOf="parent"
fab:layout_constraintRight_toRightOf="parent"
fab:layout_constraintTop_toTopOf="parent"
fab:layout_constraintVertical_bias="0.0"
fab:menu_backgroundColor="#ccffffff"
fab:menu_fab_label="Choose an action"
fab:menu_labels_colorNormal="#333333"
fab:menu_labels_colorPressed="#444444"
fab:menu_labels_colorRipple="#66FFFFFF"
fab:menu_labels_ellipsize="end"
fab:menu_labels_maxLines="-1"
fab:menu_labels_position="left"
fab:menu_labels_showShadow="true"
fab:menu_labels_singleLine="true"
fab:menu_openDirection="up"
android:layout_height="0dp"
android:layout_width="0dp">
<com.github.clans.fab.FloatingActionButton
android:id="@+id/shop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/store"
fab:fab_label="Store" />
</com.github.clans.fab.FloatingActionMenu>
关于如何解决它的任何想法?应该如何正确制作?
Any ideas on how to fix it? How should it be properly made?
推荐答案
解决方案是将app:maxImageSize = "56dp"
属性设置为您的FAB大小.
The solution is app:maxImageSize = "56dp"
property set to your FAB size.
- Have an image or vector asset, preferably in perfect circle shape and perfectly fit to canvass (no empty margins).
- Know the actual size of Floating Action Bar (FAB) - Default (56 x 56dp) or Mini (40 x 40dp).
- XML Code thusly:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:src="@drawable/perfect_fit_circle_image"
app:maxImageSize="56dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
这篇关于如何设置“浮动操作按钮"图像以填充按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文