我使用androidsvg-1.2.1.jar來渲染svg圖像。圖像的原始尺寸寬度爲260像素,高度爲100像素。我試圖成比例地設置圖像的寬度與顯示器的寬度如下:如何在AndroidSVG中使用方法setDocumentViewBox()
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
height = (int) (width/2.6);
svg.setDocumentHeight(height);
svg.setDocumentWidth(width);
svg.setDocumentViewBox(0, 0, width, height);
該文檔說,方法getDocumentHeight
,setDocumentWidth
和方法setDocumentViewBox
接受以像素爲單位的輸入值。但在這種情況下,viewbox有估計的大小,但圖片本身位於視圖框的左上角,其大小遠小於視圖框的大小(小於大約四倍)。
當我改變了代碼的最後一行的
svg.setDocumentViewBox(0, 0, width/4, height/4);
圖片的大小已成爲直逼大小視框,但仍有點小。這是爲什麼發生?應該對setDocumentViewBox
方法的輸入應用什麼值?