0

我想从图库中选择图像并在活动中的 imageview 中设置相同大小的图像,但我编写了代码,但它没有在 imageview 中以相同大小显示。它的显示很小。如何以相同的尺寸实现。

这是它设置的imageview大小

mainImageView.setLayoutParams(new LayoutParams(VirtualMirrorActivity.convertDpToPixel(270,this),VirtualMirrorActivity.convertDpToPixel(280, this)));

mainImageView.setBackgroundResource(R.layout.border);
LinearLayout linearLayout=(LinearLayout)findViewById(R.id.linearLayout);
linearLayout.addView(mainImageView);

从图库中选择图像的意图。

Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

startActivityForResult(Intent.createChooser(intent, "Select Picture"),10);

if (requestCode == 10 && resultCode == Activity.RESULT_OK) 
            {             
                Uri contentUri = data.getData();          
                String[] proj = { MediaStore.Images.Media.DATA };         
                Cursor cursor = managedQuery(contentUri, proj, null, null, null);         
                int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);         
                cursor.moveToFirst();         
                imageUri = Uri.parse(cursor.getString(column_index));

                InputStream stream = getContentResolver().openInputStream(data.getData());
                tempBitmap = BitmapFactory.decodeStream(stream);
                mainImageView.setImageBitmap(tempBitmap);

                if(tempBitmap!=null)
                {
                    isModel = false;
                    VMAdjustFrame.issaved = false;
                    isPhotofromAccount = false;
                    isPhotoChanged = true;
                }
            }
        }
4

1 回答 1

1

mainImageView.setLayoutParams().height = 270 mainImageView.setLayoutParams().width= 270

图像大小

删除它并尝试上面的代码 mainImageView.setLayoutParams(new LayoutParams(VirtualMirrorActivity.convertDpToPixel(270,this),VirtualMirrorActivity.convertDpToPixel(280, this)));

于 2012-11-25T09:00:17.337 回答