Glide的覆盖不是缩小图像

时间:2015-12-07 02:53:50

标签: android android-glide

我有一个图片视图:

<?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/image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

如果我有一个pic节目,我会使用滑行,而pic会占用整个视图:

ImageView iv = (ImageView) findViewById(R.id.image);
Glide.with(getApplicationContext())
   .load(path)
   .centerCrop()
   .into(iv);

然而,有时我没有照片,我只是想显示一个图标。图标是一种资源。我希望图标在图像视图中居中,但我不希望图标占据整个视图(它会太大)。我正在尝试使用覆盖方法在视图中使图标变小。

Glide.with(getApplicationContext())      .load(R.drawable.ic_picture_icon)      .override(250,250)      .skipMemoryCache(true)//仅用于测试,因此不会从缓存中提取      .diskCacheStrategy(DiskCacheStrategy.SOURCE)//再次用于测试      .into(IV);

但是我不能让这个工作。我正在尝试做什么?如果是这样,我做错了什么。提前谢谢。

1 个答案:

答案 0 :(得分:0)

将ImageView layout_height和layout_width更改为wrap_content可以解决问题。