Search code examples
android-studiolayoutscalescaletransform

setScaleX / setScaleY to a decimal value


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?


Solution

  • 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.