Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats up with setScaleX/setScaleY?

While trying to find a solution for the layout that I want, I came across the setScaleX/setScaleY methods, which are members of the View class.

View class doc

Now looking at the methods of RelativeLayout and filtering by the API Level 8, since I'm developing an App for >= 2.2, the said methods fade out. But when looking at "Inherited XML Attributes From Class android.view.View" the properties android:scaleX/android:scaleY are still available. Unfortunately trying to use these properties doesn't work and Eclipse says: "error: No resource identifier found for attribute 'scaleX' in package 'android'"

RelativeLayout class doc

So it seems like the documentation is contradictory and scaleX/scaleY are not available until 3.0 or am I missing something?

like image 240
taymless Avatar asked Apr 20 '11 08:04

taymless


5 Answers

NineOldAndroid is deprecated according to it's github link NineOldAndroid

Use Android Support library instead of NineOldAndroid

so you should use ViewCompatinstead of ViewHelper

simply change:

view.setScaleX(2);

or

ViewHelper.setScaleX(view,2);

to:

ViewCompat.setScaleX(view,2);

hope it helps

like image 154
Amir Hossein Ghasemi Avatar answered Nov 14 '22 21:11

Amir Hossein Ghasemi


I met a similar problem when I tried to set the view with an initial scaleX value before playing any animations, however view.setScaleX() is since API Level 11 accroding to @Dr.J .

If you want to use the Honeycomb Animation API in earlier API Levels, do have a try with NineOldAndroids at http://nineoldandroids.com/ . Based on this opensource lib, there is a workaround to provide the view an initial scaleX.

    ObjectAnimator.ofFloat(getMyButton(), "scaleX", 1f, 0f).setDuration(1).start();
like image 30
Evi Song Avatar answered Nov 14 '22 20:11

Evi Song


Ok, it looks like this is a false representation in the docs, as it's explained here scaleX/scaleY are properties added to the View class with Honeycomb and therefore unfortunately not available in Froyo.

like image 33
taymless Avatar answered Nov 14 '22 21:11

taymless


nope, the Docs are right:

public void setScaleX (float scaleX) Since: API Level 11

Froyo is API Level 8.

like image 34
Dr.J Avatar answered Nov 14 '22 21:11

Dr.J


Use the com.nineoldandroids.view.ViewHelper for older APIs:

ViewHelper.setScaleY(myButton, 0.01f);
like image 2
Eduard Avatar answered Nov 14 '22 21:11

Eduard