我必須從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 –