Ich versuche, ein Bild mit Glide zu laden, aber irgendwie kann ich das Bild nicht mit Glide laden. Wie es folgenden Fehler zeigt:
GeneratedAppGlideModule konnte nicht gefunden werden. Sie sollten eine AnnotationProcessor-Kompilierungsabhängigkeit von com.github.bumptech.glide: compiler in Ihre Anwendung aufnehmen, und eine mit @GlideModule kommentierte AppGlideModule-Implementierung oder LibraryGlideModules werden stillschweigend ignoriert.
Ich habe auch auf diese Lösung verwiesen. Aber ich habe bereits die aktualisierte Version von Glide.
In meinem Gradle habe ich hinzugefügt
implementation 'com.github.bumptech.glide:glide:4.7.1'
Und
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
Code
XML
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".view.SettingActivity">
<data>
<variable
name="settingsViewModel"
type="com.sevenbits.android.mvvmsample.viewmodel.SettingsViewModel"/>
</data>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash_bg">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="@color/white"
android:elevation="10dp"
android:orientation="vertical"
android:padding="5dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_margin="10dp"
app:image_url="@{settingsViewModel.imageUrl}"
app:civ_border_width="2dp"
app:civ_border_color="@color/colorPrimary"/>
...
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>
CustomBindingAdapter
public class CustomBindingAdapter {
@BindingAdapter({"bind:image_url"})
public static void loadImage(ImageView imageView, String url) {
RequestOptions requestOptions = new RequestOptions();
requestOptions=requestOptions.placeholder(R.drawable.boy_32);
Glide.with(imageView.getContext())
.load(url)
.apply(requestOptions)
.into(imageView);
}
5 Antworten
Schließlich fand ich meine Antwort hier.
Was habe ich getan :
Schritt 1
Ich habe eine leere Klasse mit dem Namen GlideApp
erstellt
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;
@GlideModule
public class GlideApp extends AppGlideModule {
}
Hinweis: Vergessen Sie nicht, die Anmerkung @GlideModule
hinzuzufügen.
Schritt 2 Danach habe ich das Projekt erstellt / neu erstellt und dann Glide
durch GlideApp
ersetzt. Jetzt muss RequestOptions
nicht mehr verwendet werden.
public class CustomBindingAdapter {
@BindingAdapter({"bind:image_url"})
public static void loadImage(ImageView imageView, String url) {
// RequestOptions requestOptions = new RequestOptions();
// requestOptions=requestOptions.placeholder(R.drawable.boy_32);
GlideApp.with(imageView.getContext())
.load(url)
.placeholder(R.drawable.boy_32)
.into(imageView);
// Glide.with(imageView.getContext())
// .load(url)
// .apply(requestOptions)
// .into(imageView);
}
}
Bearbeiten: Für AndroidX und Glide Version 4.9.0:
In gradle.build meiner App:
implementation ("com.github.bumptech.glide:glide:4.9.0") {
exclude group: "com.android.support"
}
annotationProcessor 'androidx.annotation:annotation:1.0.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation ("com.github.bumptech.glide:glide:4.9.0@aar") {
transitive = true
}
In meinen gradle.properties:
android.enableJetifier=true
android.useAndroidX=true
Das ist alles.
Kotlin-Lösung:
Stellen Sie sicher, dass Sie Folgendes in Ihre Gradle-Datei einfügen (ersetzen Sie annotationProcessor durch kapt source):
repositories {
mavenCentral()
google()
}
dependencies {
implementation 'com.github.bumptech.glide:glide:4.8.0'
kapt 'com.github.bumptech.glide:compiler:4.8.0'
}
Fügen Sie Ihrer Anwendung GlideSource (
import android.content.Context
import com.bumptech.glide.GlideBuilder
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.module.AppGlideModule
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.signature.ObjectKey
@GlideModule
class AppNameGlideModule : AppGlideModule() {
override fun applyOptions(context: Context, builder: GlideBuilder) {
super.applyOptions(context, builder)
builder.apply { RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL).signature(ObjectKey(System.currentTimeMillis().toShort())) }
}
}
Verwenden Sie bei der Verwendung von Glide GlideApp anstelle von Glide . Beispiel:
GlideApp.with(context)
.load(url)
.into(imageView)
Ich habe dieses Problem mit Glide:4.9.0
mit AndroidX
konfrontiert löste es so
In Ihren gradle.properties
android.useAndroidX = true
android.enableJetifier=true
In Ihrem build.gradle
//Glide dependency
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
Fügen Sie dann Ihr CustomGlideModule
hinzu @GlideModule
public class CustomeGlideModule extends AppGlideModule {}
Der letzte Schritt generiert das GlideModule
Build >> Projekt erstellen und Sie sollten das generierte Modul in Ihrem Build-Ordner sehen
Alle obigen Antworten sind wahr und funktionieren gut
Aber ich bemerkte, dass bei Verwendung der Methode #placeholder und #error der Gleitflug ohne die oben erwähnte Build-Klasse GlideModule einwandfrei funktioniert
Beispiel: Bei Verwendung funktioniert Gleiten wie dieses nicht und muss GlideModule erstellen
Glide.with(this)
.load(uri)
.into(imageView);
Und das funktioniert gut
Glide.with(this).load(uri).placeholder(android.R.drawable.progress_indeterminate_horizontal).error(android.R.drawable.stat_notify_error).into(imageView);
Zusätzlich zu Ridhis Antwort:
Damit es richtig funktioniert, musste ich isManifestParsingEnabled
einschließen.
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;
@GlideModule
public class MyGlideApp extends AppGlideModule {
@Override
public boolean isManifestParsingEnabled() {
return false;
}
}
Neue Fragen
android
Android ist Googles mobiles Betriebssystem, mit dem digitale Geräte (Smartphones, Tablets, Automobile, Fernseher, Wear, Glass, IoT) programmiert oder entwickelt werden. Verwenden Sie für Themen im Zusammenhang mit Android Android-spezifische Tags wie Android-Intent, Android-Aktivität, Android-Adapter usw. Verwenden Sie für andere Fragen als Entwicklung oder Programmierung, die sich jedoch auf das Android-Framework beziehen, diesen Link: https: // android.stackexchange.com.