我使用Universal Image Loader(UIL)缓存并在列表视图中显示图像。
我无法使用以下布局显示图像以查看列表视图
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
我想在图片的描述上方显示图片。图像的宽度是设备的整个宽度,图像的高度会根据图像的宽度自动缩放。
使用&#34; wrap_content&#34;对于宽度和高度,我可以在其他不使用UIL的项目中显示我的图像。我不确定在UIL的配置中我做错了什么(我在他们的Github的例子中使用相同的配置),但是图像不是用上面的布局进行的。实际上它们显示为0高度。如果我提供固定高度,我可以让它们显示,如
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="300dp"
/>
如果您有任何解决方案,请与我们联系。
答案 0 :(得分:1)
我设法在图像视图附加到图像视图(onLoadingComplete)后根据位图的尺寸手动更新图像视图的宽度和高度,图像的尺寸也会重新计算到旋转设备时适合新屏幕的尺寸。
如果您有任何改进此解决方案的建议,如果您有任何其他解决方案,请发表评论。谢谢!
private static class AnimateFirstDisplayListener extends SimpleImageLoadingListener {
static final List<String> displayedImages = Collections.synchronizedList(new LinkedList<String>());
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (loadedImage != null) {
ImageView imageView = (ImageView) view;
boolean firstDisplay = !displayedImages.contains(imageUri);
if (firstDisplay) {
FadeInBitmapDisplayer.animate(imageView, 500);
displayedImages.add(imageUri);
}
// Screen's width will be the width of the image.
float newWidth = Resources.getSystem().getDisplayMetrics().widthPixels;
// Get the width and the height of the image.
int oldWidth = imageView.getDrawable().getIntrinsicWidth();
int oldHeight = imageView.getDrawable().getIntrinsicHeight();
// Calculate the new height of the image based on the screen's width.
float newHeight = newWidth * oldHeight / oldWidth;
// Apply the new width and height values to ImageView.
imageView.getLayoutParams().width = (int) newWidth;
imageView.getLayoutParams().height = (int) newHeight;
}
}
}
答案 1 :(得分:0)
我已经解决了这个问题,只是尝试这样做:
key