kyleduo / SwitchButton

A cute widget of Switch Button for you to create beautiful and friendly UI.
4.72k stars 866 forks source link

layout_width and layout height is't not work,always the same size #96

Open juziml opened 7 years ago

juziml commented 7 years ago

when I use layout_width=200dp or layout height=50dp in xml file I realize it's always the same size i changed code in onMeasure method,but is't not work I need you help thanks!

huang-xinjie commented 7 years ago

I have this problem, too. It took me a day, but it didn't work out..

And I try to use app:kswThumbWidth="18dp" app:kswThumbHeight="18dp", but nothing changed.

kyleduo commented 7 years ago

Since SwitchButton use kswBackMeasureRatio to determine how width the background to be drawn with, layout_width and layout_height do change the view bounds but SwitchButton will also draw the background and thumb as they were assigned with kswThumbWidth, kswThumbHeight and kswBackMeasureRatio. If you want to change the real drawn size, use these 3 attributes instead. I'll think about improving the measuring and drawing calculation. Thanks for your feedback.

huang-xinjie commented 7 years ago

Yes, I've already used them app:kswAnimationDuration="300" app:kswBackDrawable="@drawable/ios_back_drawable" app:kswThumbDrawable="@drawable/ios_thumb_selector" app:kswBackMeasureRatio="1.7" app:kswThumbMarginBottom="-8dp" app:kswThumbMarginLeft="-6dp" app:kswThumbMarginRight="-8dp" app:kswThumbMarginTop="-5dp" app:kswThumbWidth="18dp" app:kswThumbHeight="18dp"

but it's always the same size. It's too big, in my layout. I tried all kinds of ways I could think of it, but ~~

thanks!

===========================================

And I've tried to use setThumbSize in code, but app has stopped.

kyleduo commented 7 years ago

Maybe you put your drawable in wrong directory.

huang-xinjie commented 7 years ago

OMG!!! You're right!! It works!! It works!! thank you so much!!

kyleduo commented 7 years ago

You are welcome~ By now, SwitchButton use Drawable's minimal size, usually it's instinct size, to determine the thumb size. May be I should increase the priority of kswThumbWidth and kswThumbHeight to override the Drawable's size with them, I'll think about it as well.

huang-xinjie commented 7 years ago

Support you, thank you very much for releasing this cool project. It's awesome!

maxglu commented 7 years ago

Hi! @kyleduo thanks for excelent switch, its perfect. I have the same issue. I read messages above and found temporary solution with using images with different size. But I think

increase the priority of kswThumbWidth and kswThumbHeight

it will be a perfect idea.

kyleduo commented 7 years ago

New version has released and I suggest having a try.

maxglu commented 7 years ago

Thank you!