Skip to content Skip to sidebar Skip to footer

Extra Margin(spacing) Around Floatingactionbutton Only On Api 19

I'm experiencing an extra margin or spacing around FloatingActionButton but only on API19. Screenshot on API19: Margin is correct on every other version, see screenshot below: Th

Solution 1:

You can programmatically remove margin from floatingActionButton like.It is a known issue and it is because of extra margin.

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) stream_toggle_btn.getLayoutParams();
    params.setMargins(0, 0, 0, 0); 
    stream_toggle_btn.setLayoutParams(params);

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) path_btn.getLayoutParams();
    params.setMargins(0, 0, 0, 0); 
    path_btn.setLayoutParams(params);
}

EDIT

Try to use this properties inside FloatingActionButtonxml.

app:elevation="0dp"app:pressedTranslationZ="0dp"

Like

<android.support.design.widget.FloatingActionButton
    android:id="@+id/path_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="12dp"
    android:layout_marginRight="12dp"
    android:layout_marginTop="12dp"
    android:background="@null"
    app:backgroundTint="@color/blue_light"
    app:srcCompat="@drawable/ic_line"
    app:elevation="0dp"
    app:pressedTranslationZ="0dp"/>

Solution 2:

This is because special padding implementation in the FAB on pre-Lollipop devices.

You can use

app:useCompatPadding="true"

to override this behavior.

boolean: true if FloatingActionButton is adding inner padding on platforms Lollipop and after, to ensure consistent dimensions on all platforms.

Post a Comment for "Extra Margin(spacing) Around Floatingactionbutton Only On Api 19"