2017-08-31 29 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; 
} 
相关问题