2012-03-03 86 views
0

我有我的應用程序一個精靈動畫,它的工作罰款標準的手機屏幕尺寸,但每當我把它放在一個平板電腦動畫變得出問題,不看的權利都沒有。我認爲這與圖像的高度和寬度有關。我已經嘗試將它們設置爲dp和sp,但它們仍然無法在平板電腦上正確顯示。雪碧圖像渲染不正確的Android平板電腦

這裏是我的動畫XML

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center_horizontal" 
    android:paddingLeft="100dp" > 

    <view 
     android:id="@+id/animation" 
     android:layout_width="180dp" 
     android:layout_height="220dp" 
     class="com.scale.AndroidAnimation" /> 
</LinearLayout> 

這裏是我的動畫代碼

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); 
    } 
} 

哪裏初始化

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); 

我的處理程序,它的進展

public void run() { 
    mHandler.removeCallbacks(myTimerTask); 

    if (mCurrScreen == WAITING_SCREEN) { 
     mHandler.postDelayed(myTimerTask, 300); 
    } 

    anim.update(); 
    anim.invalidate(); 
} 

提前感謝!

回答

0

它是設計用於在res tablet.Create佈局XLARGE文件夾單獨的佈局,並把它用於平板電腦屏幕優化的新佈局animation.xml文件好辦法。