Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extra padding around Floating Action Button Android

enter image description here

I am trying to make a profile page in Android. I am using a floating action Button to display user picture.

Initially i want to display a default picture.

My xml code goes like this:

<android.support.design.widget.FloatingActionButton
    android:layout_height="100dp"
    android:layout_width="100dp"
    android:id="@+id/userIcon"
    app:fabSize="normal"
    android:src="@drawable/male_icon"
    app:pressedTranslationZ="12dp"
    app:layout_anchor="@id/app_bar"
    app:layout_anchorGravity="bottom|center" />

My question is why there is some extra space around the FAB. Cant i remove that space/padding?

EDITED:

here is my full xml code::

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/app_bar_height"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:background="@drawable/background"
        app:contentScrim="#2678AD"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.PopupOverlay" />
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_scrolling" />

<android.support.design.widget.FloatingActionButton
    android:layout_height="100dp"
    android:layout_width="100dp"
    android:id="@+id/userIcon"
    app:fabSize="normal"
    android:src="@drawable/male_icon"
    app:pressedTranslationZ="12dp"
    app:layout_anchor="@id/app_bar"
    app:layout_anchorGravity="bottom|center" />

like image 966
Adarsh Raj Avatar asked Aug 04 '16 13:08

Adarsh Raj


2 Answers

u might want to change the scaletype attribute to center. Like,

android:scaleType="center"
like image 101
AbiDoll Avatar answered Sep 27 '22 20:09

AbiDoll


You can remove the extra padding by allowing your icon to be larger in size. This way you can set the icon to be the size of the floating action button.

    app:maxImageSize="40dp"

or whatever size you want to give it.

like image 39
Mars Avatar answered Sep 27 '22 20:09

Mars