关于android:使用通用图片下载器在图片视图中设置大图片

Set large image in image view using universal image downloader

我在具有以下配置的应用程序中使用通用图像下载器-

1
2
3
4
5
6
7
8
9
10
 ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
       .memoryCacheExtraOptions(1000, 1200)
       .threadPoolSize(4)
       .threadPriority(Thread.MIN_PRIORITY + 2)
       .denyCacheImageMultipleSizesInMemory()
       .memoryCache(new LruMemoryCache(1024*1024*5)) // You can pass your own memory cache implementation
       .discCacheFileNameGenerator(new HashCodeFileNameGenerator())
       .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
       .build();
       ImageLoader.getInstance().init(config);

现在要在列表中显示的图像可以是任何尺寸,可以是高分辨率图像或分辨率较低的图像,但是我要显示的图像宽度为=设备宽度,高度为-固定高度,例如-300dp,而不会模糊或拉伸图像。
是否可以创建这种视图.Instagram正在使用此过程。请参见下图-

enter


尝试一下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class CustomImageView extends ImageView {
int width = 300;// just setting random value
int height = 300;// pixels
Context context;


public CustomImageView(Context context) {
    super(context);
    this.context = context;
    this.width = getWidthOfScreen();
}

public CustomImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;
    this.width = getWidthOfScreen();
}

public CustomImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    this.context = context;
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    setMeasuredDimension(width, height);//the most important line
}

public int getWidthOfScreen() {
    WindowManager wm = (WindowManager) context
            .getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    return display.getWidth();
}
}

这里,宽度是屏幕的宽度,高度根据需要是恒定的。