-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fresco强大但不完善,所有图片加载替换成Glide。原因如下(暂时发现这些):
1、Fresco没有直接给ImageView加载图片的方式,必须使用SimpleDraweeView。(这点不应该,大概是我没有找到方法而已,比如可以直接用ImageRequest,然后将图片下到sd卡然后用ImageView去加载,从而曲线救国。) 2、使用SimpleDraweeView加载网络图片时,如果用ActivityCompat.startActivity跳到下一个页面,在第二个页面里面图片加载不出来,而如果直接startActivity()则可以。使用Glide给ImageView加载图片的方式,ActivityCompat.startActivity时可以正常显示。 3、SimpleDraweView无法自动计算ImageView的宽高,图片和ImageView的宽高适配效果感人。 如果SimpleDraweView在xml文件中将宽、高设置成wrap_content的话,需要设置宽高比来使其正常显示,否则宽高始终为0: mSimpleDraweeView.setAspectRatio(1f);
- Loading branch information
1 parent
049469a
commit a3edfaf
Showing
12 changed files
with
106 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/src/main/java/com/aishang5wpj/juhenews/utils/ImageUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.aishang5wpj.juhenews.utils; | ||
|
||
import android.widget.ImageView; | ||
|
||
import com.aishang5wpj.juhenews.R; | ||
import com.bumptech.glide.DrawableTypeRequest; | ||
import com.bumptech.glide.Glide; | ||
|
||
/** | ||
* Created by wpj on 16/5/24上午9:31. | ||
* http://blog.csdn.net/shangmingchao/article/details/51125554 | ||
*/ | ||
public class ImageUtils { | ||
|
||
private ImageUtils() { | ||
|
||
} | ||
|
||
public static ImageUtils getInstance() { | ||
return LazyHolder.INSTANCE; | ||
} | ||
|
||
public void display(ImageView imageView, String url) { | ||
|
||
display(imageView, url, R.mipmap.ic_photo_size_select_actual_white_24dp | ||
, R.mipmap.ic_photo_size_select_actual_white_24dp); | ||
} | ||
|
||
public void display(ImageView imageView, String url, int loadingImg, int errorImg) { | ||
if (imageView == null) { | ||
throw new IllegalArgumentException("argument error"); | ||
} | ||
DrawableTypeRequest request = Glide.with(imageView.getContext()).load(url); | ||
if (0 != loadingImg) { | ||
request.placeholder(loadingImg); | ||
} | ||
if (0 != errorImg) { | ||
request.error(errorImg); | ||
} | ||
request | ||
.thumbnail(0.5f)//缩略图和大图的比例系数,如果缩略图先被加载出来则先显示缩略图 | ||
.fitCenter() | ||
// .centerCrop() | ||
.crossFade() | ||
.dontAnimate()//解决加载出来的瞬间闪一下的问题 | ||
.into(imageView); | ||
} | ||
|
||
private static final class LazyHolder { | ||
private static final ImageUtils INSTANCE = new ImageUtils(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.