gpt4 book ai didi

android - SimpleDraweeView 在 fresco 中缩放图像后不调整大小

转载 作者:太空宇宙 更新时间:2023-11-03 12:30:43 25 4
gpt4 key购买 nike

我正在使用 fresco 在 ListView 中显示图像。但是我有一个问题。

当我使用像 CENTER_CROP 这样保持宽高比的方法缩放我的图像时,缩放后的图像高度变得小于我的 simpledraweeview 的高度,simple-Drawee-View 不会自动调整大小以匹配缩放图像的大小。

  • 我尝试过使用 android:adjustViewBounds = true 但它不起作用。
  • 我也试过下面的方法,但是 scaleY 我想用来计算缩放高度 返回 1 即使图像高度小于 simpe-drawee - View 的高度

    float[] f = new float[9]
    draweeView.getImageMatrix().getValues(f);
    float scaleY = f[Matrix.MSCALE_Y];
    Log.d("App","scale y is "+ scaleY);

上面的codlet在下面的方法中使用

private void loadImage(Uri fileUri,final SimpleDraweeView draweeView,int myImageHeight){

draweeView.getLayoutParams().width = displayWidth;

int selectedSize = (myImageHeight > displayWidth)? displayWidth : myImageHeight;

draweeView.getLayoutParams().height= selectedSize;


GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(context.getResources());

GenericDraweeHierarchy hierarchy = builder
.setProgressBarImage(new CircleProgressBarDrawable())
.setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP)
.build();


ImageRequest requestBuilder = ImageRequestBuilder.newBuilderWithSource(fileUri)
.setProgressiveRenderingEnabled(true)
.build();

//ImagePipeline imagePipeline = Fresco.getImagePipeline();

DraweeController controller = Fresco.newDraweeControllerBuilder()
.setOldController(draweeView.getController())
.setImageRequest(requestBuilder)
.build();
draweeView.setHierarchy(hierarchy);
draweeView.setController(controller);

float[] f = new float[9]
draweeView.getImageMatrix().getValues(f);
float scaleY = f[Matrix.MSCALE_Y];
Log.d("App","scale y is "+ scaleY);
}

结果:红色表示未填充图像的简单受票人 View 部分。这是比例类型 FIT_CENTER。当我使用 CENTER_CROP 时,图像会填满整个 ImageView ,图像的某些部分会被切掉,我不希望这样

fresco simpe drawee view not resizing

问:如何获得缩放后的图像大小并使用它来调整我的 simpleDraweeView 的大小,或者换句话说,我如何让我的 simpleDraweeView 调整它的大小?

我将不胜感激。

最佳答案

为了调整 simpledraweeview 的大小,我实现了一个 ControllerListener 并根据需要更改了 simpleDraweeView 的高度。

private void loadImage(Uri fileUri,final SimpleDraweeView simpeDraweeView) {

GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(context.getResources());

GenericDraweeHierarchy hierarchy = builder
.setProgressBarImage(new CircleProgressBarDrawable())
.setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP)
.build();


ImageRequest requestBuilder = ImageRequestBuilder.newBuilderWithSource(fileUri)
.setProgressiveRenderingEnabled(true)
.build();


ControllerListener<ImageInfo> contollerListener = new BaseContollerListener<ImageInfo>() {

public void onFinalImageSet(String id, ImageInfo imageinfo,Animatable animatable) {

if(imageinfo != null) {
updateViewSize(imageinfo)
}
}

DraweeContoller contoller = Fresco.newDraweeContollerBuilder()
.setContollerListener(contollerListener)
.setImageRequest(requestBuilder)
.build();

simpleDraweeView.setHierarchy(hierarchy);
simpleDraweeView.setController(contoller);

}

private void updateViewSize(ImageInfo imageinfo){
//this is my own implementation of changing simple-drawee-view height
// you canhave yours using imageinfo.getHeight() or imageinfo.getWidth();
simpleDraweeView.getLayoutParams().height = imageinfo.getHeight();

// don't forget to call this method. thanks to @plamenko for reminding me.

simpleDraweeView.requestLayout()
}

关于android - SimpleDraweeView 在 fresco 中缩放图像后不调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34874463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com