我想为这样的对象设置动画: 现在我的问题是:如何测量(b)在不退出屏幕的情况下为我的对象(o)设置动画?
对象o;
nextX = random.nextInt(b);
ObjectAnimator a1;
a1 = ObjectAnimator.oFFloat(o,“x”,nextX)
答案 0 :(得分:0)
您可以获得屏幕高度和宽度
public static int getScreenHeight(Context ctx) {
DisplayMetrics metrics = ctx.getResources().getDisplayMetrics();
return metrics.heightPixels;
}
public static int getScreenWidth(Context ctx) {
DisplayMetrics metrics = ctx.getResources().getDisplayMetrics();
return metrics.widthPixels;
}
并像这样使用
Random randX = random.nextInt(getScreenWidth(ctx));
Random randY = random.nextInt(getScreenheight(ctx));
ObjectAnimator moveX = ObjectAnimator.ofFloat(object, "x", randX );
ObjectAnimator moveY = ObjectAnimator.ofFloat(object, "y", randY );