[英]How to get image width and height dynamically while zooming in android?
我使用以下方法動態查找圖像的寬度和高度。但是,在放大和縮小圖像時,我得到了相同的值。我也使用這種方法來檢索圖像寬度:-float width = imag.getWidth() 。 為此,也會顯示相同的值。我在xml文件中將圖像寬度設置為300dp。
image.setOnTouchImageViewListener(new OnTouchImageViewListener() {
@Override
public void onMove() {
RectF rect = image.getZoomedRect();
currentZoom = image.getCurrentZoom();
Drawable d = image.getDrawable();
Bitmap bmp = ((BitmapDrawable)d).getBitmap();
currwidth = bmp.getWidth();
currheight = bmp.getHeight();
calculate(currwidth);
MarginLayoutParams params = (MarginLayoutParams) animImag.getLayoutParams();
params.leftMargin =(int)calculate(currwidth); params.topMargin = (int)calculate(currwidth);
animImag.setLayoutParams(params);
}
});
我認為您必須嘗試image.getMeasuredWidth和height。 適當大小的圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.