setScaleX / setScaleY to a decimal value

370 Views Asked by At

When setting the scale of a view programmatically, setScaleX() and setScaleY() do not accept decimal values like "0.1" and displays the error code "setScaleX(float) in View cannot be applied to (double)" when such a value is specified.

setScaleX() and setScaleY() only seems to accept integers like 1, -5 or 10.

How do you set this scale value to a decimal amount?

2

There are 2 best solutions below

1
smhily On BEST ANSWER

NOTE: This solution was incredibly easy, but I thought I would post this question anyway in case someone else was having the same problem.

Simply add an " f " to the end of the value within the brackets of setScaleX() / setScaleY().

It will look something like this:

button.setScaleY(0.1f);

Hope this helps someone.

0
waghydjemy On

Because you are putting a double as an entry for setScaleX() methode so you should cast it to float

try this :

yourView.setScaleX((float) yourDoubleVariable);