11

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?

Onik
  • 19,396
  • 14
  • 68
  • 91
taymless
  • 779
  • 2
  • 9
  • 24

6 Answers6

5

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();
Evi Song
  • 862
  • 11
  • 14
3

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

Amir Hossein Ghasemi
  • 20,623
  • 10
  • 57
  • 53
3

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.

taymless
  • 779
  • 2
  • 9
  • 24
3

nope, the Docs are right:

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

Froyo is API Level 8.

Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335
Dr.J
  • 1,220
  • 8
  • 9
  • Yeah, the methods will be hidden when you select any API level below 11. But the Inherited XML Attributes From Class android.view.View won't, so that the attributes are still there, as you can see in the RelativeLayout doc Btw. [Froyo is level 8](http://source.android.com/source/build-numbers.html) – taymless Apr 21 '11 at 08:08
  • yes, but it is looking for the scaleX's resource which in this case is going to be the setScaleX handle, which is not available (as set during Build Target). Your build target is 2.2 I assume? if it is 3.0 and it's giving you this error then it's a bug. – Dr.J Apr 21 '11 at 08:18
  • I think we're talking past each other ;) My build target is 2.2 and I can't use neither the methods nor the xml attributes for scaling. I was confused by the documentation, since it says the methods are not available but the xml attributes are. That's what I wanted to know. So I'd say the "bug" is in the documentation... – taymless Apr 21 '11 at 08:25
  • the documentation is a bit flimsy at certain places, it does say `android:scaleX Since: API Level` what ever API that is :X – Dr.J Apr 21 '11 at 08:28
2

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

ViewHelper.setScaleY(myButton, 0.01f);
Eduard
  • 3,482
  • 2
  • 27
  • 45
0

For anyone interested: I only zoom in to center of canvas and this code works for me:

public float[] getAbsolutePosition(float Ax, float Ay) {

    float fromAxToBxInCanvasSpace = (screenwidth/2 - Ax) / zoomLevel;
    float fromBxToCanvasEdge = screenwidth/2;
    float x = screenwidth - fromAxToBxInCanvasSpace - fromBxToCanvasEdge;

    float fromAyToByInCanvasSpace = (screenheight/2 - Ay) / zoomLevel;
    float fromByToCanvasEdge = screenheight/2;
    float y = screenheight - fromAyToByInCanvasSpace - fromByToCanvasEdge;

    return new float[] { x, y };
}