使用universial image loader时(如果是本地资源方法类似),从网络上获取的图片,图片是一个图文详情,就是很高的一张图,我希望这张图宽度填充屏幕,高度自适应,可采用以下方法:
ImageLoader.getInstance().displayImage(imageurl, ivPicTextDetail, new ImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
// TODO Auto-generated method stub
DisplayMetrics metric = displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metric);
int pxWidth = metric.widthPixels;
float ratio = (float)pxWidth/(float)loadedImage.getWidth();
float imageHeight = loadedImage.getHeight()*ratio;
ViewGroup.LayoutParams lp = ivPicTextDetail.getLayoutParams();
lp.width = pxWidth;
lp.height = (int)imageHeight;
ivPicTextDetail.setLayoutParams(lp);
}
});
xml配置为:
<ImageView
android:id="@+id/iv_pic_text_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitStart" />