SwitchButton icon indicating copy to clipboard operation
SwitchButton copied to clipboard

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

Open juziml opened this issue 7 years ago • 10 comments

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!

juziml avatar Aug 02 '17 02:08 juziml

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.

huang-xinjie avatar Aug 03 '17 10:08 huang-xinjie

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.

kyleduo avatar Aug 04 '17 03:08 kyleduo

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.

huang-xinjie avatar Aug 04 '17 04:08 huang-xinjie

Maybe you put your drawable in wrong directory.

kyleduo avatar Aug 04 '17 04:08 kyleduo

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

huang-xinjie avatar Aug 04 '17 04:08 huang-xinjie

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.

kyleduo avatar Aug 04 '17 04:08 kyleduo

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

huang-xinjie avatar Aug 04 '17 04:08 huang-xinjie

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.

maxglu avatar Oct 12 '17 10:10 maxglu

New version has released and I suggest having a try.

kyleduo avatar Nov 02 '17 06:11 kyleduo

Thank you!

maxglu avatar Nov 10 '17 14:11 maxglu