android 布局图片缩放,Android中进行图片缩放显示

Android中进行图片缩放显示:

demo下载连接:

http://download.csdn.net/detail/u011084603/9370368

b414f65519c78753a6b40d43532cf0e5.png

实现步骤:

1、使用ImageLoader 加载网络图片

universal-image-loader-1.9.3.jar 自行下载

2、用于显示图片 待缩放功能的自定义ImageView:

直接下载工程demo查看即可,

demo下载连接:

http://download.csdn.net/detail/u011084603/9370368

3、添加网络请求的权限:

4、MainActivity.java中自定义对话框用于单独显示图片,进行缩放推拽显示:

/**

* 加载网络图片

*/

public void lookPid() {

String bmPath = "http://pic10.nipic.com/20101014/4768360_230901509000_2.jpg";

final Dialog dialog = new Dialog(MainActivity.this);

WindowManager.LayoutParams params = dialog.getWindow().getAttributes();

params.width = WindowManager.LayoutParams.WRAP_CONTENT;

params.height = WindowManager.LayoutParams.WRAP_CONTENT;

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

dialog.setCancelable(true);

dialog.setContentView(R.layout.zoom_image);

ImageView iv = (ZoomImageView) dialog.findViewById(R.id.iv_pic);

ImageLoader.getInstance().displayImage(bmPath, iv,

new ImageLoadingListener() {

@Override

public void onLoadingStarted(String arg0, View arg1) {

progressDialog.show();

}

@Override

public void onLoadingFailed(String arg0, View arg1,

FailReason arg2) {

progressDialog.dismiss();

}

@Override

public void onLoadingComplete(String arg0, View arg1,

Bitmap arg2) {

progressDialog.dismiss();

dialog.show();

}

@Override

public void onLoadingCancelled(String arg0, View arg1) {

progressDialog.dismiss();

}

});

}

5、imageLoader在使用时需要初始化:

/**

* universal-ImageLoager 初始化

*/

public void initImageLoader() {

DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()

.cacheInMemory(true) // 设置下载的图片是否缓存在内存中

.cacheOnDisk(true) // 设置下载的图片是否缓存在SD卡中

.considerExifParams(true) // 是否考虑JPEG图像EXIF参数(旋转,翻转)

.imageScaleType(ImageScaleType.EXACTLY)// 设置图片以如何的编码方式显示

// .bitmapConfig(Bitmap.Config.ARGB_8888)// 设置图片的解码类型

.bitmapConfig(Bitmap.Config.RGB_565)// 设置图片的解码类型

.build();

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(

getApplicationContext())

.defaultDisplayImageOptions(defaultOptions)

.threadPriority(Thread.NORM_PRIORITY - 2)

.denyCacheImageMultipleSizesInMemory()

.discCacheFileNameGenerator(new Md5FileNameGenerator()).build();

ImageLoader.getInstance().init(config);

}

6、所需的布局文件:

zoom_image.xml:

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:background="#e0000000"

android:gravity="center"

android:orientation="vertical" >

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_gravity="center"

android:minHeight="80dp"

android:minWidth="80dp"

android:scaleType="matrix" />

LinearLayout>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值