简体   繁体   中英

Android Floating Action button : Resize inside icon

在此处输入图片说明

Hi I want to set image into FloatingActionButton i did this :

<android.support.design.widget.FloatingActionButton
            android:id="@+id/qick_menu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="20dp"
            android:src="@drawable/quick_menu"
            app:elevation="7dp"
            app:layout_anchor="@id/mapview"
            app:layout_anchorGravity="bottom|right|end" />

But I have a small image in my button

try this: in Layout:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="0dp"
        android:scaleType="fitXY"
        android:src="@drawable/map"
        app:backgroundTint="@android:color/transparent"
        app:borderWidth="0dp"
        app:useCompatPadding="true" />


</RelativeLayout>

Now in res/values/dimens.xml:

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="fab_margin">16dp</dimen>
    <dimen name="design_fab_image_size" tools:override="true">56dp</dimen>
</resources>

This line is important <dimen name="design_fab_image_size" tools:override="true">56dp</dimen>

output:

在此处输入图片说明

您可以使用fabSize 属性

app:fabSize="normal" 

Try this: android:scaleType="center" and try image size 56dp. It worked for me.

The image/icon inside FAB can be resized in XML.

app:maxImageSize = "32dp" This will be your image size inside Floating Action Button.

app:fabCustomSize = "64dp" This will be your Floating Action Button size.

如果您想更改内部图像的大小,您可以更改图像,只需选择您选择的图像并将其添加到浮动按钮即可。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM