在android中開發圖片浏覽器,能否像iPhone一樣,能對不規格的圖片進行滑動! android中規格的圖片能夠滑動,但是如果是不規格的圖片,要顯示就不能做滑動了,這是怎麼回事?下面是我的源碼
-----------------------------------------------------------------------------------------------------------------------------------------------------------
public void doDraw(Canvas canvas) {
if (mSurfaceHolder == null || canvas == null) {
return;
}
canvas.drawColor(Color.BLACK);
Paint p = new Paint();
Bitmap b = null;
if (OffsetX < 0) {
if (nBitmap != null) {
// canvas.drawBitmap(nBitmap, scalX + 1 + OffsetX, OffsetY, p);
b = nBitmap;
}
} else if (OffsetX > 0) {
if (fBitmap != null) {
// canvas.drawBitmap(fBitmap, -scalX - 1 + OffsetX, OffsetY, p);
b = fBitmap;
}
}
if (bitmap != null && OffsetX <= slideWidth) {
b = bitmap;
// canvas.drawBitmap(bitmap, OffsetX, OffsetY, p);
}
float aa = 1;
if(b.getHeight() > b.getWidth()) {
if(b.getHeight() > scalY) {
aa = (float)b.getHeight() / scalY;
}
} else if(b.getHeight() < b.getWidth()) {
if(b.getWidth() > scalX) {
aa = (float)b.getWidth() / scalX;
}
}
rect = new RectF(0, 0, scalX / aa , scalY / aa);
canvas.drawBitmap(bitmap, null, rect, p);
}