Android 如何使用Glide v4.0.0RC1从Url将图像加载到ImageView中

Android 如何使用Glide v4.0.0RC1从Url将图像加载到ImageView中,android,android-glide,Android,Android Glide,我刚刚在我的应用程序中将Glide库从v3更新到v4。 但现在我无法从url加载图像。以前,它在v3上运行良好 这是我的滑行代码: Glide.with(context).load(galleryList.get(itemPosition).getImage()).thumbnail(Glide.with(context).load(R.drawable.balls)).apply(options).into(holder.kolamImage); v4的变化是什么?我浏览了文档,但仍然没有任

我刚刚在我的应用程序中将Glide库从v3更新到v4。 但现在我无法从url加载图像。以前,它在v3上运行良好

这是我的滑行代码:

Glide.with(context).load(galleryList.get(itemPosition).getImage()).thumbnail(Glide.with(context).load(R.drawable.balls)).apply(options).into(holder.kolamImage);

v4的变化是什么?我浏览了文档,但仍然没有任何帮助。

如果您使用的是Glide v4.0.0-RC1,则需要使用
RequestOptions
添加占位符、错误图像和其他选项。下面是一个工作示例

Glide.with(this)
        .load("url here") // image url
        .placeholder(R.drawable.placeholder) // any placeholder to load at start
        .error(R.drawable.imagenotfound)  // any image in case of error
        .override(200, 200) // resizing
        .centerCrop()     
        .into(imageView);  // imageview object
RequestOptions options = new RequestOptions()
                    .centerCrop()
                    .placeholder(R.mipmap.ic_launcher_round)
                    .error(R.mipmap.ic_launcher_round);



 Glide.with(this).load(image_url).apply(options).into(imageView);

Glide v4添加了
RequestOptions
功能,以添加占位符、错误图像和自定义图像

RequestOptions options = new RequestOptions()
                    .placeholder(R.drawable.your_placeholder_image)
                    .error(R.drawable.your_error_image);

Glide.with(this).load(image_url).apply(options).into(imageView);

确保url周围有引号,ivProfileImage是您的imageview

Glide.with(mContext)
    .asBitmap()
    .load("https://i2.wp.com/www.siasat.com/wp-content/uploads/2018/03/Rosamund-Pike.jpeg?fit=600%2C421&ssl=1")
    .into(ivProfileImage);

以下步骤用于将图像从URL加载到imageView:-

创建一个像这样的新活动,并从给定的url加载图像

活动\u main.xml

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

    <ImageView
        android:id="@+id/myOfferImage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:scaleType="fitXY" />

</LinearLayout>

尝试登录galleryList.get(itemPosition).getImage(),您也可以在
.into()之前添加一个
.listener()
图像url。但这张图片无法通过Glide下载。我正在调用
适配器
onBindViewHolder()
中的上述行。早些时候,它与V3M一起工作可能与损坏的缓存有关glide也缓存从internet加载的图像吗?我可以在gridview中使用它吗@是的,你可以。我可以在gridview中使用这个吗?
public class MainActivity extends AppCompatActivity {


    ImageView myOfferImageView;
    String url = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        url = "https://image.url"


        myOfferImageView = findViewById(R.id.myOfferImage);
        Glide.with(this).load(url)
                .placeholder(R.drawable.ic_launcher_background)
                .error(R.drawable.ic_launcher_background)
                .into(myOfferImageView);
    }


}