medyo / Fancybuttons

Icons, Borders, Radius ... for Android buttons
1.77k stars 397 forks source link

Vector drawable cannot be used in the button #68

Closed suku-h closed 6 years ago

suku-h commented 8 years ago

I tried using a vector drawable as an iconResource. While the vector drawable is rendering, it is not picking up the condition for position and the text is not being displayed.

<mehdi.sakout.fancybuttons.FancyButton android:id="@+id/fworkouttype_fb_musclegain" android:layout_width="@dimen/d_250" android:layout_height="@dimen/d_80" android:textAllCaps="false" android:textStyle="bold" fancy:fb_text="@string/musclegain" fancy:fb_textSize="@dimen/s_24" fancy:fb_textColor="@color/white" fancy:fb_textGravity="center" fancy:fb_iconResource="@drawable/vector_musclegain" fancy:fb_iconPosition="left" fancy:paddingStart="@dimen/d_10" fancy:paddingEnd="@dimen/d_10" fancy:fb_iconPaddingTop="@dimen/d_10" fancy:fb_iconPaddingBottom="@dimen/d_10" fancy:fb_defaultColor="@color/positive" fancy:fb_focusColor="@color/positiveClicked" fancy:fb_radius="@dimen/d_40"/>

The output of using the vector drawable fb_vector

This is the same code using a png: <mehdi.sakout.fancybuttons.FancyButton android:id="@+id/fworkouttype_fb_weightloss" android:layout_width="@dimen/d_250" android:layout_height="@dimen/d_80" android:textAllCaps="false" android:textStyle="bold" fancy:fb_text="@string/weightloss" fancy:fb_textSize="@dimen/s_24" fancy:fb_textColor="@color/white" fancy:fb_iconResource="@drawable/play" fancy:fb_iconPosition="left" fancy:paddingStart="@dimen/d_10" fancy:paddingEnd="@dimen/d_10" fancy:fb_iconPaddingTop="@dimen/d_10" fancy:fb_iconPaddingBottom="@dimen/d_10" fancy:fb_defaultColor="@color/positive" fancy:fb_focusColor="@color/positiveClicked" fancy:fb_radius="@dimen/d_40"/>

output of using png: fb_png

It would be great if your library could support vector drawables. I am planning to make all my png icons into vector drawables.

medyo commented 8 years ago

Hi @suku-h, that's really weird, I just tried on my own and it works like a charm !

here is my example :

<mehdi.sakout.fancybuttons.FancyButton
android:id="@+id/btn_instagram"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:padding="10dp"
fancy:fb_borderColor="#FFFFFF"
fancy:fb_borderWidth="2dp"
fancy:fb_defaultColor="#40a75a"
fancy:fb_focusColor="#8cc9f8"
fancy:fb_textGravity="center"
fancy:fb_iconResource="@drawable/icon_instagram"
fancy:fb_fontIconSize="30sp"
fancy:fb_iconPosition="left"
fancy:fb_text="Instagram"
fancy:fb_radius="10dp"
fancy:fb_textColor="#FFFFFF"/>    
suku-h commented 8 years ago

I tried your code but this is the output I get when I used vector drawable:

medyoreply

You can get the vector drawable here that I used.

Does it have to do with different phones? Or Marshmellow?

suku-h commented 8 years ago

I went through your code. The problem is caused because your are inflating the imageview with WRAP_CONTENT layouts. The WRAP_CONTENT size for this image is 591px, hence the imageview is inflating to that size but the fancybutton is limited by the size of the dimensions assigned.