我有一个包含图像URL的JSON文件,然后我使用Glide intoCardView来显示它们 Java:
Glide
.with(context)
.load(post.getImgUrl())
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target,
boolean isFromMemoryCache, boolean isFirstResource) {
mProgress.hide();
return false;
}
})
.priority(Priority.HIGH)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(image);
_xml:_
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:id="@+id/cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
card_view:cardPreventCornerOverlap="false"
app:ignore="NamespaceTypo">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
</android.support.v7.widget.CardView>
现在我希望获得JSON中每个图像的宽度和高度,将其设置为 ImageView (高度,宽度)
所以我已经尝试过了:
int width = resource.getIntrinsicWidth();
int height = resource.getIntrinsicHeight();
但它对我不起作用