setScaleX/setScaleY 是怎么回事?

发布于 2024-11-02 14:01:49 字数 631 浏览 3 评论 0原文

在尝试为我想要的布局找到解决方案时,我遇到了 setScaleX/setScaleY 方法,它们是 View 类的成员。

View 类文档

现在看看RelativeLayout 和按API级别8进行过滤,因为我正在开发> = 2.2的应用程序,所以上述方法逐渐消失。但是,当查看“从 android.view.View 类继承的 XML 属性”时,属性 android:scaleX/android:scaleY 仍然可用。不幸的是,尝试使用这些属性不起作用,Eclipse 说:“错误:在包'android'中找不到属性'scaleX'的资源标识符”

RelativeLayout 类文档

所以看起来文档是矛盾的,scaleX/scaleY 直到 3.0 才可用,还是我错过了什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

帅哥哥的热头脑 2024-11-09 14:01:50

不,文档是正确的:

public void setScaleX (float scaleX) 自:API 级别 11

Froyo 是 API 级别 8。

nope, the Docs are right:

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

Froyo is API Level 8.

记忆消瘦 2024-11-09 14:01:50

NineOldAndroid弃用,根据其 github 链接 NineOldAndroid

使用 Android 支持库 而不是 NineOldAndroid

因此您应该使用 ViewCompat 而不是ViewHelper

只需将:

view.setScaleX(2);

ViewHelper.setScaleX(view,2);

更改为:

ViewCompat.setScaleX(view,2);

希望有帮助

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

云朵有点甜 2024-11-09 14:01:50

对于较旧的 API,请使用 com.nineoldandroids.view.ViewHelper

ViewHelper.setScaleY(myButton, 0.01f);

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

ViewHelper.setScaleY(myButton, 0.01f);
影子是时光的心 2024-11-09 14:01:50

对于任何感兴趣的人:我只放大到画布中心,此代码对我有用:

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

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 };
}
因为看清所以看轻 2024-11-09 14:01:49

当我尝试在播放任何动画之前设置具有初始scaleX值的视图时,我遇到了类似的问题,但是view.setScaleX()是自API级别11起根据@Dr.J。

如果您想在早期 API 级别中使用 Honeycomb 动画 API,请尝试使用 http://nineoldandroids.com/ 上的 NineOldAndroids。基于此开源库,有一种解决方法可以为视图提供初始scaleX。

    ObjectAnimator.ofFloat(getMyButton(), "scaleX", 1f, 0f).setDuration(1).start();

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();
泪冰清 2024-11-09 14:01:49

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文