如何动态更改帧速率或动画的FPS?

时间:2016-05-15 09:26:15

标签: android animation rotation frame-rate

我正在创建一个应用程序,它可以在10秒内360度旋转方形。现在它具有默认帧速率。但我想改变它的帧速率,但它应该在10秒内旋转360度。意味着无论什么帧速率它都应该在10秒内完成360度。

我正在使用视图和绘图来执行此操作。 还有其他办法吗?

先谢谢。 这是我的代码。

 public class Square extends View  {

private Rect rect;
private Paint paint;
float height1;
float width1;

 public Square(Context context)
 {

     super(context);
     DisplayMetrics displaymetrics = new DisplayMetrics();
     ((Activity)      getContext()).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
      int height = displaymetrics.heightPixels;
     int width = displaymetrics.widthPixels;
     height1=height;
     width1=width;

    Point cos = new Point(width/2,height/2);
     int left = cos.x-(200);
    int top = cos.y - 200;
     int right =cos.x+200;
     int bottom = cos.y+200;

     rect = new Rect(left,top,right,bottom);

     // create a rectangle that we'll draw late rect = new Rect(x, y,  sideLength, sideLength);

     // create the Paint and set its color
    paint = new Paint();






 }


 protected void onDraw(final Canvas canvas) {


    super.onDraw(canvas);
  /* canvas.drawColor(Color.BLACK);
    canvas.drawRect(rect, paint);*/
    //canvas.drawColor(Color.BLACK);
    long time1 = System.nanoTime();
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.WHITE);
    canvas.drawRect(rect, paint);


    // border
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.GREEN);
    canvas.drawRect(rect, paint);

    long ti = animate().getDuration();
    String x = "hello";

    //Log.e("Tag",x+ti);

    long lsttime = System.nanoTime();
    double fps = 100000000.0 / (lsttime - time1);
    animate().rotation(360).setDuration(10000).start();


    String fpss = "" + fps;
    Log.e("Tag", fpss);
  }

}  

0 个答案:

没有答案