Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android在视图下绘制动画_Android_Android Layout_Android Animation_Android View - Fatal编程技术网

android在视图下绘制动画

android在视图下绘制动画,android,android-layout,android-animation,android-view,Android,Android Layout,Android Animation,Android View,我有层次结构: Buttons (Button childs) myView (View child) RelativeView (has background image) 在myView中,我绘制具有动画(缩放0.5到1.0大小)的圆,它的性能非常低(绘制速度非常慢) 我不能使用surfaceview,因为surfaceview在任何视图下都不能透明,如果它是 透明它必须是surface.setZOrderOnTop(true) 怎么办 附言 绘图代码 // S

我有层次结构:

Buttons  (Button childs)
   myView (View child)
      RelativeView (has background image)
在myView中,我绘制具有动画(缩放0.5到1.0大小)的圆,它的性能非常低(绘制速度非常慢)

我不能使用surfaceview,因为surfaceview在任何视图下都不能透明,如果它是
透明它必须是
surface.setZOrderOnTop(true)

怎么办

附言

绘图代码

    // Square is Button that need to has animated circle under it
for (int i = 0; i < squares.size(); i++) {
        Square square = squares.get(i);
        if (square.animIndex == -1)
            continue;
        int left = square.getLeft();
        int top = getRelativeTop(square);

        int w = (int) (square.animIndex * square.getMeasuredWidth() * 4 / 10f);

        square.animIndex++;

        if (square.animIndex > 10) {
            square.animIndex = -1;
        }
              //note is circle bitmap
        c.drawBitmap(note, null, new Rect(left - w / 2 + square.getMeasuredWidth() / 2, top - w / 2
                + square.getMeasuredHeight() / 2, left - w / 2 + square.getMeasuredWidth() / 2 + w, top
                - w / 2 + square.getMeasuredHeight() / 2 + w), null);
    }
//正方形是一个按钮,下面需要有一个动画圆圈
对于(int i=0;i10){
平方指数=-1;
}
//注意是圆形位图
c、 drawBitmap(注意,空,新矩形(左-w/2+square.getMeasuredWidth()/2,上-w/2
+square.getMeasuredHeight()/2,左-w/2+square.getMeasuredWidth()/2+w,顶部
-w/2+square.getMeasuredHeight()/2+w),空);
}

如果没有看到完整的代码,就很难看出瓶颈的原因是什么,从你的问题中也不太清楚你到底想画什么,所以我只能给你一些提示

如果您张贴的代码是<代码> OnDebug()/Case>方法,那么我将考虑将所有计算移出到另一个后台线程中。因为

onDraw()
是在主(GUI)线程中执行的,所以您应该尽可能少地进行计算,即位图应该准备好转储到屏幕上,并且任何参数都应该作为变量可用,即不要在
onDraw()
中调用
getMeasuredHeight()

你也在做演员:

int w=(int)(square.animIndex*square.getMeasuredWidth()*4/10f)

如果可以,请避免混合浮点和整数,但同样,请从onDraw()方法中获取此计算


最后,由于'onDraw()'在主线程中运行,因此您必须避免在线程中进行计算。这将导致你的应用程序无响应/迟钝,因此你的用户将卸载。你想画的东西可能没什么问题,只是你怎么画才是问题的根源。

你怎么画你的圈?你能发布你的代码吗?你在哪里执行下一个循环?请同时发布onDraw()方法。