A couple of days ago I had the perfect FAB, now the image won't be centered and it's driving me crazy! this is what I got now:
i'm using the button inside a CardView. this is the button xml tag:
<android.support.design.widget.FloatingActionButton
android:id="@+id/btn_options"
style="@style/fab"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="@dimen/fab_margin"
android:layout_marginTop="20dp"
android:elevation="10dp"
android:scaleType="center"
android:src="@drawable/ic_options"
android:tint="@color/colorPrimary"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintTop_toTopOf="parent" />
and this is the drawable file: ic_options.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
</vector>
weird thing is, when I change the FAB width and height to wrap_content, it gets centered properly but the button gets bigger and I don't want that.. like this:
this problem happened after I made some changes in the whole project, depending on Android Studio Inspector. But, this layout wasn't changed and I just have no idea what happened to it!
Do you have any idea?
Edit:
CardView code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
style="@style/AppTheme"
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_gravity="top"
app:ignore="NamespaceTypo"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="12dp"
card_view:cardCornerRadius="2dp"
>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="400dp"
android:layout_height="220dp"
android:contentDescription="@string/contentDescription_mapBackground"
android:foreground="@drawable/map_overlay" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/fab_margin"
card_view:layout_constraintEnd_toStartOf="@+id/btn_options"
card_view:layout_constraintStart_toStartOf="parent">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:letterSpacing="0.04"
android:textColor="@color/colorWhite"
android:textSize="17sp" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:drawableStart="@drawable/ic_marker2"
android:drawableTint="@color/white"
android:textColor="@color/colorWhite"
android:textSize="12sp" />
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/btn_options"
style="@style/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/fab_margin"
android:layout_marginTop="20dp"
android:elevation="10dp"
android:scaleType="center"
android:src="@drawable/ic_options"
android:tint="@color/colorPrimary"
app:fabCustomSize="40dp"
card_view:layout_constraintTop_toTopOf="parent"
card_view:layout_constraintEnd_toEndOf="parent"
/>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>


