开发者

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 'androi开发者_如何学运维d'"

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?


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();


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.


nope, the Docs are right:

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

Froyo is API Level 8.


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


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

ViewHelper.setScaleY(myButton, 0.01f);


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 };
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜