Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Floating Action button : Resize inside icon

Tags:

java

android

enter image description here

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

like image 412
Krzysztof Pokrywka Avatar asked Mar 13 '17 09:03

Krzysztof Pokrywka


4 Answers

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.

like image 165
Shoaib Khalid Avatar answered Nov 10 '22 01:11

Shoaib Khalid


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:

enter image description here

like image 40
rafsanahmad007 Avatar answered Nov 09 '22 23:11

rafsanahmad007


you can use fabSize attribute

app:fabSize="normal" 
like image 43
Farid Avatar answered Nov 10 '22 00:11

Farid


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

like image 25
Andrew Glukhoff Avatar answered Nov 09 '22 23:11

Andrew Glukhoff