Why is my floating action button not displaying properly?

早过忘川 提交于 2019-12-25 08:23:47

问题


My floating button image looks like this

It's a smaller button inside a larger circle, How do I fix this?

layout file:

 <android.support.design.widget.FloatingActionButton
    android:id="@+id/addToKitchenButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="16dp"
    android:layout_gravity="bottom|end"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:src="@drawable/ic_add_circle_black_50dp"
    />

vector code:

  <vector android:height="50dp" android:viewportHeight="24dp"
    android:viewportWidth="24dp" android:width="50dp" xmlns:android="http://schemas.android.com/apk/res/android">

    <path android:fillColor="#FF000000" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM17,13h-4v4h-2v-4L7,13v-2h4L11,7h2v4h4v2z"/>

</vector>

回答1:


I answered your previous question so I think I have realised what you missed here. Have a look at this image. You have accidentally added the Add circle. Add the selected one with 24dp or 48dp with white color it will work

]1


回答2:


Got Solution For You But I am not recommend it

create one vector file for icon color ic_circle.xml

<?xml version="1.0" encoding="utf-8"?><vector android:height="40dp" android:viewportHeight="24"
android:viewportWidth="24" android:width="40dp" xmlns:android="http://schemas.android.com/apk/res/android">

<path android:fillColor="@android:color/black" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM17,13h-4v4h"/></vector>

create second vector file for same color of float button your ic_add_circle_black_50dp.xml

<vector android:height="50dp" android:viewportHeight="24"
android:viewportWidth="24" android:width="50dp" xmlns:android="http://schemas.android.com/apk/res/android">

create layer-list entries let say layer_list.xml

<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_circle" android:top="5dp" android:left="5dp" android:right="5dp" android:bottom="5dp" android:gravity="center"/>
<item android:drawable="@drawable/ic_add_circle_black_50dp"
    android:height="55dp" android:width="55dp"/></layer-list>

Now Modify your FloatButton in xml as

<android.support.design.widget.FloatingActionButton
    android:id="@+id/addToKitchenButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="16dp"
    android:layout_gravity="bottom|end"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:src="@drawable/layer_list" />


来源:https://stackoverflow.com/questions/39737699/why-is-my-floating-action-button-not-displaying-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!