【发布时间】:2018-09-28 19:25:16
【问题描述】:
我正在尝试使用 glide 加载图像,但不知何故我无法使用 glide 加载图像。因为它显示以下错误:
未能找到 GeneratedAppGlideModule。您应该在应用程序中包含对 com.github.bumptech.glide:compiler 的 annotationProcessor 编译依赖项,并且 @GlideModule 注释的 AppGlideModule 实现或 LibraryGlideModules 将被静默忽略。
我也推荐了This solution。但是,我已经有了 glide 的更新版本。
在我的gradle中,我添加了
implementation 'com.github.bumptech.glide:glide:4.7.1'
和
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
代码
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);
}
【问题讨论】:
-
请提供应用级别和项目级别的 build.gradle 文件代码。
标签: android data-binding android-glide