Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid View animation - poor performance on big screens
    primarykey
    data
    text
    <p>I developed a puzzle game. In my game I have several custom views, which are nested inside FrameLayout, like layers. Each view displays a bitmap. The largest bitmap is the game board and it takes about 2/3 of screen size. There is also background image under the FrameLayout. </p> <p>When user touches the screen, simple view animations are performed with this game board view - it can be rotated or flipped.</p> <p>It all works fine on small screens, but users reported performance issues on Galaxy Tab - there's a noticeable lag just before animation starts and animation itself is not smooth. (Game board bitmap size on these screens is about 600*600px)</p> <p>Here's my layout:</p> <pre><code>&lt;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" &gt; &lt;ImageView android:id="@+id/backgroundImageLayer" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/background" android:scaleType="fitXY"/&gt; &lt;FrameLayout android:id="@+id/gameFrame" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;com.mygame.BoardView android:id="@+id/boardLayer" android:layout_width="fill_parent" android:layout_height="fill_parent"/&gt; &lt;com.mygame.SomeObjectView android:id="@+id/someObjectLayer" android:layout_width="fill_parent" android:layout_height="fill_parent"/&gt; &lt;com.mygame.SomeOtherObjectView android:id="@+id/someOtherObjectLayer" android:layout_width="fill_parent" android:layout_height="fill_parent"/&gt; &lt;/FrameLayout&gt; &lt;/FrameLayout&gt; </code></pre> <p>And here is my BoardView class.</p> <pre><code>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); } } </code></pre> <p>And a snippet where I do the animation, it's pretty simple:</p> <pre><code>AnimationRotate anim1=new AnimationRotate(startAngle,endAngle,centerX,centerY); anim1.setDuration(500); anim1.setInterpolator(newDecelerateInterpolator()); startAnimation(anim1); </code></pre> <p>So what causes lags with view animation and how can I fix it? Is my approach correct or maybe I should use SurfaceView or frame animation or something else?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload