android - 在 Grid View Android 中使用 Glide 时图像被垂直拉伸(stretch)

标签 android android-activity android-gridview android-glide

我制作了一个应用程序,可以在 GridView 中显示本地存储的图像。我曾经使用 Picasso,但由于许多问题(它没有在某些设备上加载图像)而停止使用它。然后我切换到 glide,一切很好,除了图像被垂直拉伸(stretch)。这会导致滚动问题。我在使用 Picasso 时从未遇到过这样的问题。我该如何解决这个问题???

我的 MainActivity 代码-

 Glide.with(MainActivity.this)
                    .load(mThumbIds[position])
                    .placeholder(R.raw.place_holder)
                    .error(R.raw.big_problem)
                    .centerCrop()
                    .into(imageView);
            return imageView;

我的activity_main.xml文件代码

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

    <GridView
    android:id="@+id/gridview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:columnWidth="150dp"
    android:numColumns="2"
    android:layout_above="@+id/adView" />

    <com.google.android.gms.ads.AdView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/adView"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/banner_ad_unit_id"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">
    </com.google.android.gms.ads.AdView>

 </RelativeLayout>

问题截图- See the image on the right it is stretched vertically

最佳答案

我才知道。 这是因为占位符图像的大小与原始图像不匹配。

我的解决方案是简单地删除占位符或调整占位符的大小

关于android - 在 Grid View Android 中使用 Glide 时图像被垂直拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33463147/

相关文章:

java - 如何阻止用户在完成 Activity 后在设定的时间内单击按钮

startup - 如何禁用所有自动启动的应用程序

android - 如果 Activity 被操作系统杀死,我们如何检索保存的状态?

android - 如何优化要在 GridView 中使用的自定义 ImageView?

android-gridview - Gridview onScroll 方法总是被调用,没有用户滚动

java - 使用项目旋转 Android GridView

android - 广播接收器中 SEND 操作的 Intent 过滤器

android - 在android中以编程方式启动电子邮件客户端并将电子邮件地址传递给客户端

android - 在 AlarmReceiver 中调用其他 Activity 的方法

java - Android - 无法解析符号 "R"