Thursday 15 May 2014

android - Using Hardware Layer in Custom View onDraw -


So I'm trying to understand that the hardware acceleration in the custom view <(when available) / code > Which is constantly animating it is my base of onDraw () :

  canvas.drawColor (mBackgroundColor); (Layer layer: malair) {canvas.save (); Canvas.translate (layer.x, layer.y); // Draw the number of images in a grid, offset for -1 (int i = -1; i and lieuten; layer.xcount - 1; i ++) {for (int j = -1; j & lt ; Layer.yCount - 1; J ++) {canvas.drawBitmap (layer.bitmap, layer.w * i, layer.h * j, null); }} // If the layer's X has moved to its width, then reset it back to a seamless position layer. X + = ((difference * layer.xSpeed) / 1000f); Float xOverlap = layer.x% layer.w; If (avlap> gt; 0) {layer.x = xOverlap; } // If the layer's Y is lagging behind its height, then reset it back to an uninterrupted position layer. Y + = ((difference * layer.ySpeed) / 1000f); Float yOverlap = layer.y% layer.h; If (yOverlap> 0) {layer.y = yOverlap; } Canvas.restore (); } // Radra View View ViewCompat.postInvalidateOnAnimation (this);   

I am enabling the hardware levels in on Attachtovondo () and disabling them on onDetachedFromWindow () , but Whether or not I'm trying to understand I'm actually using it, basically, i / j the loop that calls drawBitmap () never changes; The only thing that changes is that the canvas is translated bitmap is automatically saved as a texture behind the scenes, or manually to do so Need to do something?

Which view (s) are you looking at . PLAYER_LAYER_TYHE_HARDWARE OK? If you are installing a hardware layer on the view with the drawing code shown above, then you're doing the system more than necessary. Since you are only portraying bitmap, you do not need to do anything. If you call Canvas.drawBitmap () , then the resulting OpenGL texture will be cached on your behalf.

You can customize your code a little bit more, instead of calling drawBitmap () , you can use child thoughts if you have these codes for offset If you go ahead using * () methods (or setX () / setY () ), the framework will implement further customization Draw () methods to refrain from calling again.

In general, the hardware layers should be set to the scenes that are expensive to attract and whose content will not be changed often (unlike what you are doing too much :)

No comments:

Post a Comment