Note that there are some explanatory texts on larger screens.

plurals
  1. POFlickering TranslateAnimation/ScaleAnimation on a custom View
    primarykey
    data
    text
    <p>I implemented a custom <code>View</code> which applies a custom <code>ScaleAnimation/TranslateAnimation</code> via the <code>getTransformation()</code> of the animation. I.e. the application zooms in to a certain point of a bigger bitmap (the bitmap is bigger than the screen). On higher resolution devices (such as the Samsung Galaxy S3, which is x-hdpi), the zoom (actually scale+translate) process <strong>flickers</strong> and stutters strongly. (More precisely, many <strong>parts</strong> of the image flicker, other parts are OK. E.g. text captions contained in the image flicker.) There is some flickering on other devices too, such as Desire HD. (Note that the custom View is required, because later, I apply other custom animations on it too, but that is irrelevant now.)</p> <p>When the animation starts, the bitmap is zoomed-out (i.e. it is visible from "distance"). The animation zooms in and translates at the same time.</p> <p>I thought the bitmap might be too big (indeed it's not small), but I tried everything with no luck: I put correct versions to hdpi,xhpdi,etc., I also tried with smaller sized bitmaps, I tried downsampling via <code>decodeResource()</code>, but nothing helped.</p> <p>Actually, the custom <code>View</code> contains a custom drawable called <code>MyBackgroundDrawable</code>. The <code>MyBackgroundDrawable</code> class handles the animation and draws the transformed bitmap.</p> <p>This is the code of the <code>onDraw()</code> of the custom <code>View</code>:</p> <pre><code>@Override protected void onDraw(Canvas canvas) { canvas.drawColor(Color.WHITE); mMyBackgroundDrawable.draw(canvas); // my custom Drawable invalidate(); } </code></pre> <p>This is how I load the bitmap:</p> <pre><code>Resources res = context.getResources(); BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inScaled = false; Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.mybackground, opt); Drawable mMyDrBackground = new BitmapDrawable(res, bmp); </code></pre> <p>And this is the <code>draw()</code> method of <code>mMyBackgroundDrawable</code> (i.e. my custom <code>Drawable</code>):</p> <pre><code>@Override public void draw(Canvas canvas) { int sc = canvas.save(); sWorld.reset(); // this is a Matrix if (mMyAnimation!= null) { mMyAnimation.getTransformation(AnimationUtils.currentAnimationTimeMillis(), mTransformation); sWorld = mTransformation.getMatrix(); } sMatrix.reset(); sMatrix.preTranslate(sViewportX / 2, sViewportY / 2); sMatrix.preConcat(sWorld); sMatrix.preConcat(mPosition); canvas.setMatrix(sMatrix); mMyDrBackground .draw(canvas); canvas.restoreToCount(sc); } </code></pre> <p>Actually, <code>mMyAnimation</code> is an <code>AnimationSet</code>, and (while the flickering happens), it is playing a <code>TranslateAnimation+ScaleAnimation</code> (at the same time, because I'm zooming and moving to a certain point of the bitmap at the same time).</p> <p>Why does the flickering and stuttering happen, how can it be solved?</p> <p><strong>UPDATE</strong>: I didn't implement <code>onMeasure()</code> for the custom <code>View</code>. Can this cause such a problem? My custom view is added to this layout (i.e. to <code>layoutRoot</code>):</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/layoutRoot" &gt; &lt;/RelativeLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    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