dop*_*000 4 performance animation android
我开发了一款益智游戏.在我的游戏中,我有几个自定义视图,它们嵌套在FrameLayout中,就像图层一样.每个视图都显示一个位图.最大的位图是游戏板,大约占屏幕尺寸的2/3.FrameLayout下还有背景图像.
当用户触摸屏幕时,使用此游戏板视图执行简单的视图动画 - 它可以旋转或翻转.
这一切工作正常,在小屏幕上,但用户报告了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>
Run Code Online (Sandbox Code Playgroud)
这是我的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);
}
}
Run Code Online (Sandbox Code Playgroud)
还有我做动画的片段,很简单:
AnimationRotate anim1=new AnimationRotate(startAngle,endAngle,centerX,centerY);
anim1.setDuration(500);
anim1.setInterpolator(newDecelerateInterpolator());
startAnimation(anim1);
Run Code Online (Sandbox Code Playgroud)
那么什么导致视图动画滞后,我该如何解决?我的方法是正确的还是我应该使用SurfaceView或帧动画或其他东西?
smi*_*324 11
如果尚未启用硬件加速,请启用它.布局渲染系统在3.0+中进行了修改,通过将大部分软件渲染转移到硬件中来提高这些大屏幕的性能.你关心在这里阅读更多相关信息
有些东西不适用于硬件加速,但从你所展示的内容来看,你没问题.启用它的最简单方法是将其添加到应用程序的清单和目标3.0或更高版本(如同构建,您仍然可以支持较低的api级别)
<application android:hardwareAccelerated="true"
...
>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7912 次 |
| 最近记录: |