medyo / Fancybuttons

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

What does this.setLayoutParams() in initializeButtonContainer() for? #25

Closed mariotaku closed 9 years ago

mariotaku commented 9 years ago

https://github.com/medyo/fancybuttons/blob/master/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java#L406

This causes fancybuttons layout incorrect in layouts other than LinearLayout.

medyo commented 9 years ago

Can you attach some captures or past your code ? so i can reproduce the issue. thanks

mariotaku commented 9 years ago

just try add layout_margin to its xml attributes, you will find it won't work. maybe this should be removed?

medyo commented 9 years ago

Same sample buttons have already layout_margin and it works perfectly. https://github.com/medyo/fancybuttons/blob/master/samples/src/main/res/layout/activity_xml_buttons.xml#L27

mariotaku commented 9 years ago

I tried put it in FrameLayout, all layout params except width and height are invalid, I found LayoutParams was always set to LinearLayout.LayoutParams despite of what parent is.

medyo commented 9 years ago

Please paste the code you have tried, so i can reproduce the same scenario.

mariotaku commented 9 years ago

I can't reproduce it on a new project, but when I put fancybutton in an xml file, and inflate it runtime, It crashes. Actually after I commenting setLayoutParams out, sample code still works fine: https://github.com/mariotaku/fancybuttons

    java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to com.wefika.flowlayout.FlowLayout$LayoutParams
            at com.wefika.flowlayout.FlowLayout.onMeasure(FlowLayout.java:239)
            at android.view.View.measure(View.java:17547)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)
            at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
            at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
            at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
            at android.view.View.measure(View.java:17547)
            at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1260)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
            at android.widget.ScrollView.onMeasure(ScrollView.java:337)
            at android.view.View.measure(View.java:17547)
medyo commented 9 years ago

I've tried to run the same sample using FlowLayout Library and it works perfectly. here is my code :

<?xml version="1.0" encoding="utf-8"?>

<merge>

    <com.wefika.flowlayout.FlowLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:fancy="http://schemas.android.com/apk/res-auto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start|top"
        android:padding="10dp">

        <mehdi.sakout.fancybuttons.FancyButton
            android:id="@+id/btn_facebook_like"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:padding="10dp"
            fancy:borderColor="#FFFFFF"
            fancy:borderWidth="1dp"
            fancy:defaultColor="#3b5998"
            fancy:focusColor="#5577bd"
            fancy:fontIconResource="@string/icon_like"
            fancy:fontIconSize="10sp"
            fancy:iconPosition="right"
            fancy:radius="30dp"
            fancy:text="Like my facebook page"
            fancy:textColor="#FFFFFF"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:text="dolor" />
    </com.wefika.flowlayout.FlowLayout>

</merge>
medyo commented 9 years ago

Does this commit https://github.com/medyo/fancybuttons/pull/26 fixes your issue ?

medyo commented 9 years ago

hi @mariotaku Have you fixed the issue ?

mariotaku commented 9 years ago

@medyo I use shaped drawable for now because I can't figure out why margin is ignored. Thank you though!