Glide не отображает изображения в моем приложении для Android - PullRequest
1 голос
/ 02 мая 2019

В моем приложении у меня есть следующий код в моей captureBonus активности (где также живет ImageView):

// Process the Sample Image
bonusSampleImage = findViewById(R.id.bonusSampleImage);
Glide.with(this)
    .load("http://i.imgur.com/DvpvklR.png")
    //.load("https://www.tourofhonor.com/appimages/2019fl4.jpg")
    .into(bonusSampleImage);

Но когда я запускаю свое приложение, я не получаюлюбой вид изображения на всех.Прежде чем я добавлю приведенный выше код, появится представление изображения с его заполнителем.Кроме того, я попробовал обе ссылки в коде, ни одна из них не работает (я думал, что это связано с https).

У меня уже есть разрешения на доступ к Интернету и внешнему хранилищу.

Я обнаружил, что Glide зарегистрировал некоторыеактивность в logcat, она была доступна для просмотра только в подробном режиме, хотя:

2019-05-01 16:51:38.329 3182-3182/net.tommyc.android.tourofhonor W/Glide: Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored
2019-05-01 16:51:38.568 3182-3182/net.tommyc.android.tourofhonor I/ViewTarget: Glide treats LayoutParams.WRAP_CONTENT as a request for an image the size of this device's screen dimensions. If you want to load the original image and are ok with the corresponding memory cost and OOMs (depending on the input size), use .override(Target.SIZE_ORIGINAL). Otherwise, use LayoutParams.MATCH_PARENT, set layout_width and layout_height to fixed dimension, or use .override() with fixed dimensions.
2019-05-01 16:51:38.690 3182-3182/net.tommyc.android.tourofhonor W/Glide: Load failed for http://i.imgur.com/DvpvklR.png with size [1032x2038]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
    There was 1 cause:
    java.net.UnknownHostException(Unable to resolve host "i.imgur.com": No address associated with hostname)
     call GlideException#logRootCauses(String) for more detail
      Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE
    There was 1 cause:
    java.net.UnknownHostException(Unable to resolve host "i.imgur.com": No address associated with hostname)
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
    There was 1 cause:
    java.net.UnknownHostException(Unable to resolve host "i.imgur.com": No address associated with hostname)
     call GlideException#logRootCauses(String) for more detail
          Cause (1 of 1): class java.net.UnknownHostException: Unable to resolve host "i.imgur.com": No address associated with hostname
2019-05-01 16:51:38.690 3182-3182/net.tommyc.android.tourofhonor I/Glide: Root cause (1 of 1)

Вот соответствующий формат XML для этого действия:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:orientation="vertical"
    android:fillViewport="true">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:context=".captureBonus">

        <RelativeLayout
            android:id="@+id/basicBonusInfo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp">

            <TextView
                android:id="@+id/bonusName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/valueBonusName"
                android:layout_alignParentTop="true"
                android:layout_alignParentStart="true"
                android:textSize="18sp"/>

            <TextView
                android:id="@+id/bonusCategory"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/valueCategory"
                android:layout_below="@id/bonusName"
                android:layout_alignParentStart="true"/>

            <TextView
                android:id="@+id/bonusCode"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/valueBonusCode"
                android:layout_below="@id/bonusName"
                android:layout_alignParentEnd="true"/>

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/bonusLocationInfo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_below="@id/basicBonusInfo">

            <TextView
                android:id="@+id/bonusAddress"
                android:text="1600 Pennsylvania Ave NW"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

            <TextView
                android:id="@+id/bonusCity"
                android:text="Washington"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/bonusAddress"/>

            <TextView
                android:id="@+id/bonusState"
                android:text="DC"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:layout_below="@id/bonusAddress"
                android:layout_toEndOf="@id/bonusCity"/>

            <TextView
                android:id="@+id/bonusGPSLabel"
                android:text="GPS:"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_below="@id/bonusCity"/>

            <TextView
                android:id="@+id/bonusGPSCoordinates"
                android:text="XX.YYYYYY, -XX.YYYYYY"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_below="@id/bonusCity"
                android:layout_alignParentEnd="true" />

        </RelativeLayout>

        <ImageView
            android:id="@+id/bonusMainImage"
            android:contentDescription="@string/mainImageDescription"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/bonusLocationInfo"
            android:src="@drawable/no_image_taken"
            android:scaleType="centerInside"
            android:adjustViewBounds="true"
            android:layout_margin="8dp"
            android:clickable="true"
            android:focusable="true"/>

        <ImageView
            android:id="@+id/bonusSecondaryImage"
            android:contentDescription="@string/secondaryImageDescription"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/bonusMainImage"
            android:src="@drawable/optional_2nd_image"
            android:scaleType="centerInside"
            android:adjustViewBounds="true"
            android:layout_margin="8dp"/>

        <TextView
            android:id="@+id/additionalBonusDetails"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/lblSampleBonusImage"
            android:layout_below="@id/bonusSecondaryImage"
            android:layout_marginStart="8dp"/>

        <ImageView
            android:id="@+id/bonusSampleImage"
            android:contentDescription="@string/sampleImageDescription"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/additionalBonusDetails"
            android:src="@drawable/sample_image_missing"
            android:scaleType="centerInside"
            android:adjustViewBounds="true"
            android:layout_margin="8dp"/>

        <TextView
            android:id="@+id/bonusFlavorLabel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Bonus Notes"
            android:layout_marginStart="8dp"
            android:layout_below="@id/bonusSampleImage"/>

        <TextView
            android:id="@+id/bonusFlavorContent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="XXXXXXXXXXXXXXX"
            android:layout_margin="8dp"
            android:layout_below="@id/bonusFlavorLabel"/>

        <Button
            android:id="@+id/btnSubmitBonus"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/btnLblSubmitBonus"
            android:layout_below="@id/bonusFlavorContent"
            android:layout_centerHorizontal="true"/>

    </RelativeLayout>
</ScrollView>

Ответы [ 2 ]

2 голосов
/ 02 мая 2019

Вам не хватает s в вашем URL.Пожалуйста, используйте https вместо http для URL изображения.

Glide.with(this)
    .load("https://i.imgur.com/DvpvklR.png")  // Add https instead of http
    .placeholder(R.drawable.sample_image_missing)  // Add a placeholder here
    .into(bonusSampleImage);

И следующее в вашей зависимости в вашем build.gradle файле.Я думаю, что этого нет.

annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'

Как указано в документации Glide , вам также нужно иметь репозитории, если у вас их еще нет.

Ида, пожалуйста, проверьте ваше интернет-соединение.

0 голосов
/ 02 мая 2019
dependencies {
  implementation 'com.github.bumptech.glide:glide:4.9.0'
  annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}

repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
        maven { url 'https://maven.google.com' }
    }

Создайте класс MyGlideApp и пересоберите свой проект.

@GlideModule
public class MyGlideApp extends AppGlideModule {

    @Override
    public boolean isManifestParsingEnabled() {
        return false;
    }
}

Вставьте это в свой класс деятельности

public void loadGlideImage(Context context, ImageView imageView, String url) {
            GlideApp.with(context.getApplicationContext())
                    .load(url)
                    .signature(new ObjectKey(url))
                    .dontAnimate()
                    .into(imageView);
    }

Тогда вы можете сделать

String img_url = "https://www.tourofhonor.com/appimages/2019fl4.jpg";
loadGlideImage(this, bonusSampleImage, img_url);
...