【问题标题】:imageview in gridview wrong size, after replacing loading placeholder替换加载占位符后,gridview中的imageview大小错误
【发布时间】:2013-04-30 07:41:08
【问题描述】:

我正在使用 gridview 来显示 2 列的图像列表。

我正在使用通用图像加载器从数据库中获取图像,效果很好,但是一旦图像被加载,并且“加载图像”占位符被替换,尺寸就会缩小到图像的实际尺寸,并且没有正确填充单元格。

占位符图像已正确放大,以填充可用宽度并包裹高度。 所有图像的尺寸相同,需要放大或缩小,具体取决于屏幕尺寸。

这是列表项布局(已更新,我也有一个 textview,我认为这无关紧要,但谁知道..):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/grid_gallery_item_imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        android:src="@drawable/loading_image" />

    <TextView
        android:id="@+id/grid_gallery_item_textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/grid_gallery_item_imageView1"
        android:background="#50000000"
        android:ellipsize="end"
        android:gravity="center_vertical"
        android:maxLines="3"
        android:padding="8dp"
        android:text="Bacon ipsum."
        android:textColor="#ffffff"
        android:textSize="20sp" />

</RelativeLayout>

这是我的网格视图:

 <GridView
        android:id="@+id/grid_gallery_layout_gridView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:numColumns="2"
        android:stretchMode="columnWidth">

在我的 gridview 适配器中,我只是使用它来加载图像:

imageLoader.displayImage("db://" + item.imageId, holder.imageView, options);

选项:

options = new DisplayImageOptions.Builder().bitmapConfig(Bitmap.Config.RGB_565).showStubImage(R.drawable.loading_image)
        .displayer(new FadeInBitmapDisplayer(Constants.GRIDVIEW_IMAGE_FADEIN_TIME)).build();

这是问题的截图:

加载的图像应与占位符图像大小相同。

任何想法,为什么加载图像可能会破坏图像视图的大小?

编辑:缩小实际上可以正常工作,但放大却搞砸了。例如,在较小的屏幕上,图像尺寸正确。

【问题讨论】:

    标签: android gridview universal-image-loader


    【解决方案1】:

    看来我已经解决了这个问题。 如果 ImageView 在 gridview 内,显然 ImageView 不能正确放大图像。

    这段代码非常适合我:link

    【讨论】:

      【解决方案2】:

      我打赌你需要

      android:scaleType="centerCrop"
      

      而且不需要将单个 ImageView 放在 RelativeLayout 中

      <ImageView
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/grid_gallery_item_imageView1"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_centerInParent="true"
          android:adjustViewBounds="true"
          android:scaleType="centerCrop"
          android:src="@drawable/loading_image" />
      

      ^ 如果正确重写适配器,则不需要 id 属性,例如

      if (convertView == null) {
          convertView = inflater.inflate(id, null);
      }
      imageView = (ImageView) convertView;
      

      【讨论】:

      • 我不想裁剪图像。 imageview旁边还有一个textview,和问题无关,所以我没有加进去..
      • 啊,明白了。如果“加载”图像的高度与您希望的目标图像一样大,请确保高度。
      • 所有图片大小相同(加载占位符,真实图片)。
      • 尝试将 android:verticalSpacing="0dp" 和 android:horizo​​ntalSpacing="0dp" 添加到您的 GridView。
      • 我已经编辑了我的问题,并在列表项示例中添加了 textview,也许这很重要..
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-25
      • 2013-04-08
      • 1970-01-01
      • 2019-02-10
      • 2020-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多