Note that there are some explanatory texts on larger screens.

plurals
  1. POSprite image rendering incorrectly on android tablet
    primarykey
    data
    text
    <p>I have a sprite animation in my app and it's working fine for standard phone sized screens but whenever I put it on a tablet the animation gets glitchy and doesn't look right at all. I think it has something to do with the height and widths of the image. I've tried setting them as dp and sp but they still won't render right on the tablet. </p> <p>Here's my animation xml</p> <pre><code>&lt;LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:paddingLeft="100dp" &gt; &lt;view android:id="@+id/animation" android:layout_width="180dp" android:layout_height="220dp" class="com.scale.AndroidAnimation" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Here's my animation code</p> <pre><code>public class AndroidAnimation extends View{ private Bitmap mAnimation; private Rect mSRectangle; private int mNoOfFrames; private int mCurrentFrame; private int mSpriteHeight; private int mSpriteWidth; public AndroidAnimation(Context context, AttributeSet aSet) { super(context, aSet); mSRectangle = new Rect(0,0,0,0); mCurrentFrame = 0; } public void init(Bitmap theBitmap, int Height, int Width, int theFrameCount) { mAnimation = theBitmap; mSpriteHeight = Height; mSpriteWidth = Width; mSRectangle.top = 0; mSRectangle.bottom = mSpriteHeight; mSRectangle.left = 0; mSRectangle.right = mSpriteWidth; mNoOfFrames = theFrameCount; mCurrentFrame = 0; } public void update() { mCurrentFrame++; mCurrentFrame %= mNoOfFrames; mSRectangle.left = mCurrentFrame * mSpriteWidth; mSRectangle.right = mSRectangle.left + mSpriteWidth; } @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); Rect dest = new Rect(0, 0, mSpriteWidth, mSpriteHeight); canvas.drawBitmap(mAnimation, mSRectangle, dest, null); } } </code></pre> <p>Where I initialize it</p> <pre><code>anim = (AndroidAnimation) findViewById(R.id.animation); anim.init(BitmapFactory.decodeResource(getResources(), R.drawable.connecting_sprite), 300, 170, 3); mHandler.removeCallbacks(myTimerTask); mHandler.postDelayed(myTimerTask, 300); </code></pre> <p>My handler that progresses it</p> <pre><code>public void run() { mHandler.removeCallbacks(myTimerTask); if (mCurrScreen == WAITING_SCREEN) { mHandler.postDelayed(myTimerTask, 300); } anim.update(); anim.invalidate(); } </code></pre> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    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