我开发了一个拼图游戏。在我的游戏中,我有几个自定义视图,这些视图嵌套在FrameLayout中,就像图层一样。每个视图显示一个位图。最大的位图是游戏板,它占据了大约2/3的屏幕大小。FrameLayout下还有背景图像。
当用户触摸屏幕时,会对这个游戏板视图执行简单的视图动画-它可以旋转或翻转。
这在小屏幕上都很好用,但用户报告说在Galaxy Tab上存在性能问题-在动画开始之前有明显的延迟,并且动画本身不太流畅。(这些屏幕上的游戏板位图大小约为600 * 600px)
以下是我的布局:
那么是什么导致视图动画的延迟,我该如何解决它呢?我的方法正确吗?还是我应该使用SurfaceView或帧动画或其他东西?
当用户触摸屏幕时,会对这个游戏板视图执行简单的视图动画-它可以旋转或翻转。
这在小屏幕上都很好用,但用户报告说在Galaxy Tab上存在性能问题-在动画开始之前有明显的延迟,并且动画本身不太流畅。(这些屏幕上的游戏板位图大小约为600 * 600px)
以下是我的布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootFrame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/backgroundImageLayer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/background"
android:scaleType="fitXY"/>
<FrameLayout android:id="@+id/gameFrame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.mygame.BoardView
android:id="@+id/boardLayer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<com.mygame.SomeObjectView
android:id="@+id/someObjectLayer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<com.mygame.SomeOtherObjectView
android:id="@+id/someOtherObjectLayer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</FrameLayout>
</FrameLayout>
以下是我的 BoardView 类。
public class BoardView extends View {
Bitmap b;
int x;
int y;
public BoardView(Context context, AttributeSet attrs) {
super(context, attrs);
// calculate size of the bitmap
b = Bitmap.createBitmap(sizeX, sizeY, Bitmap.Config.ARGB_4444);
createMyBitmap();
}
private void createMyBitmap() {
Canvas c;
c = new Canvas(b);
// lots of c.drawRect() and c.drawLine() , using opaque and semi-transparent colors
}
@Override
public void onDraw(Canvas canvas) {
canvas.drawBitmap(b, x, y, null);
}
}
以下是我进行动画的代码片段,非常简单:
AnimationRotate anim1=new AnimationRotate(startAngle,endAngle,centerX,centerY);
anim1.setDuration(500);
anim1.setInterpolator(newDecelerateInterpolator());
startAnimation(anim1);
那么是什么导致视图动画的延迟,我该如何解决它呢?我的方法正确吗?还是我应该使用SurfaceView或帧动画或其他东西?