Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 图像视图中设置的位图未获得填充父对象_Android - Fatal编程技术网

Android 图像视图中设置的位图未获得填充父对象

Android 图像视图中设置的位图未获得填充父对象,android,Android,我使用以下方法压缩了图像: private Bitmap decodeFile(InputStream is){ //decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(is,null,o); //F

我使用以下方法压缩了图像:

      private Bitmap decodeFile(InputStream is){
        //decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(is,null,o);

        //Find the correct scale value. It should be the power of 2.
        final int REQUIRED_SIZE=100;
        int width_tmp=o.outWidth, height_tmp=o.outHeight;
        int scale=1;
        while(true){
            if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
                break;
            width_tmp/=2;
            height_tmp/=2;
            scale*=2;
        }

        //decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize=scale;
        return BitmapFactory.decodeStream(is, null, o2);
    }
但是没有用


还有其他办法吗?

这可能会解决问题

iv.setScaleType(ScaleType.FIT_XY);

在你的活动中使用这个

mImageView.setScaleType(ScaleType.FIT_XY);
或者在你的布局中

android:scaleType="fitXY"
android:scaleType="fitXY"