Java 如何以编程方式将ImageView定位到屏幕外

Java 如何以编程方式将ImageView定位到屏幕外,java,android,Java,Android,我需要将ImageView放置在屏幕外,以便为其设置动画,但我无法使其工作。我需要支持api 9+,并尝试了以下代码: ImageView camion = (ImageView) findViewById(R.id.camion); int amountOffscreen = (int)(camion.getWidth() * 0.8); /* or whatever */ boolean offscreen = true; /* true o

我需要将ImageView放置在屏幕外,以便为其设置动画,但我无法使其工作。我需要支持api 9+,并尝试了以下代码:

        ImageView camion = (ImageView) findViewById(R.id.camion);

        int amountOffscreen = (int)(camion.getWidth() * 0.8); /* or whatever */
        boolean offscreen = true; /* true or false */


        int xOffset = (offscreen) ? amountOffscreen : 0;
        RelativeLayout.LayoutParams rlParams = 
            (RelativeLayout.LayoutParams)camion.getLayoutParams();
        rlParams.setMargins(-1*xOffset, 0, xOffset, 0);
        camion.setLayoutParams(rlParams);

但ImageView框架保持不变

你试过使用xml动画吗?没有,从来没有试过,因为我正在考虑使用TranslateAnimation。你有任何用xml创建的动画的例子吗?也许你可以看看-这是一个动画API的后端口,所以它可以在Android 1+和更高版本上工作。。。另一方面:通过支持Api级别9,您基本上限制了自己很多,Api级别10及以下的用户约占用户群的5%。你肯定应该考虑将你的minSdkTarget向上移动……你尝试过使用xml动画吗?没有,我从来没有尝试过,因为我正在考虑使用TranslateAnimation的动画。你有任何用xml创建的动画的例子吗?也许你可以看看-这是一个动画API的后端口,所以它可以在Android 1+和更高版本上工作。。。另一方面:通过支持Api级别9,您基本上限制了自己很多,Api级别10及以下的用户约占用户群的5%。你绝对应该考虑把你的目标提高。。。