【问题标题】:Set large image in image view using universal image downloader使用通用图像下载器在图像视图中设置大图像
【发布时间】:2014-09-03 07:10:08
【问题描述】:

我在我的应用中使用通用图像下载器,配置如下 -

 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 正在使用此过程。见下图-

【问题讨论】:

  • 您可能想要创建自己的图像视图并覆盖 onmeasure 方法。这将是最简单的解决方案。
  • 感谢您的回答,我明白了,请您解释一下我该怎么做。
  • 是此设置需要大内存的问题,还是您只是在问如何将图像拉伸到屏幕尺寸?如果是后者,那么这不是与 UID 相关的问题

标签: android image bitmap image-resizing universal-image-loader


【解决方案1】:

试试这个:

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();
}
}

这里,宽度是屏幕宽度,高度是你想要的恒定值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-21
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    相关资源
    最近更新 更多