我必须从URL或文件名/ Uri中将图像加载到SimpleDraweeView
。使用Fresco从文件中以正确的高宽比加载图像
这是我的xml
布局:
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
fresco:actualImageScaleType="centerCrop"
fresco:placeholderImage="@color/wait_color"
fresco:placeholderImageScaleType="centerCrop"
fresco:roundTopLeft="true"
fresco:roundTopRight="true"
fresco:roundBottomLeft="false"
fresco:roundBottomRight="false"
fresco:roundedCornerRadius="3dp" />
当我加载从网址诸如Facebook或Instagram的图像时,得到width
和图像的height
并且基于这一点,我计算纵横比和其设置为SimpleDraweeView
这样的:
imageUrl = intent.getExtras().getString(KEY_IMAGE_URL);
int width = intent.getExtras().getInt(KEY_WIDTH);
int height = intent.getExtras().getInt(KEY_HEIGHT);
float aspectRatio = (float) width/height;
image.setAspectRatio(aspectRatio);
Uri uri = Uri.parse(imageUrl);
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
.setProgressiveRenderingEnabled(true)
.setAutoRotateEnabled(true)
.build();
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setImageRequest(request)
.setOldController(image.getController())
.build();
image.setController(controller);
现在,我需要能够加载图像到SimpleDraweeView
使用filename
或Uri
与正确长宽比,我该怎么做?
这比使用像我在我的解决方案中建议的'ControllerListener'更低效。看看https://stackoverflow.com/questions/33955510/facebook-fresco-using-wrap-conent/34075281#34075281 –