如何应用缩放控制

时间:2011-12-19 07:19:25

标签: android android-imageview

如何动态地在ImageView中应用缩放控制?我的最低SDK版本是1.6。我尝试了大部分样本,但在所有这些样本中,ImageView中的图像都设置为放大和缩小。我想放大和缩小ImageView。我想在放大时增加ImageView宽度和高度,并在缩小时减小ImageView宽度和高度。任何人都可以提出解决方案吗?

1 个答案:

答案 0 :(得分:1)

是的,这是增加大小的代码

140 is the factor by which image is mulitplied maintaining the height to width ratio
you can change this as you like


  Bitmap originalBitmap = BitmapFactory.decodeFile(IssueDataHandler.CONTENT_LOCAL_PATH+"/"+coverImageName.trim());
    Bitmap bitmap=originalBitmap;
    if (bitmap !=null) {
        int h = bitmap.getHeight();
        int w = bitmap.getWidth();
        h = 140*h/w;
        w = 140;
        bitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);
        img.setImageBitmap(bitmap);
    }