2017-08-31 30 views

回答

0

我匹配寬度方法如下

public void instantiateItem() { 
    ... 
    _ssiImageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CUSTOM); 
    _ssiImageView.setMinScale(getFitWidthScale()); 
    ... 
} 

private float getFitWidthScale(){ 
    float windowWidth = App.getWindowWidth(); //Acquires window's pixel width 
    return = windowWidth/getImageWidth(); 
} 

private float getImageWidth(){ 
    BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inJustDecodeBounds = true; 
    BitmapFactory.decodeFile(_file.getAbsolutePath(), options); 
    return options.outWidth; 
} 

這僅工作正常,如果SubsamplingScaleImageView填滿整個屏幕寬度。基本上窗口寬度和視圖寬度需要相同。但是,如果您可以獲取SubsamplingScaleImageView的像素寬度,則可以使用該寬度代替windowWidth。

0

你可以使用setImage(ImageSource imageSource, ImageViewState state)方法是這樣的:

ssiImageView.setImage(ImageSource.uri(Uri.fromFile(new File(imgFilePath))), new ImageViewState(getFitWidthScale(), new PointF(0, 0), SubsamplingScaleImageView.ORIENTATION_USE_EXIF)); 

private float getFitWidthScale(){ 
    float windowWidth = App.getWindowWidth(); //Acquires window's pixel width 
    return = windowWidth/getImageWidth(); 
} 

private float getImageWidth(){ 
    BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inJustDecodeBounds = true; 
    BitmapFactory.decodeFile(_file.getAbsolutePath(), options); 
    return options.outWidth; 
} 
相關問題