【发布时间】:2017-02-06 18:33:07
【问题描述】:
当我尝试将图像设置为从资产文件夹浏览的ImageView 时遇到问题。当我将相同的图像放在可绘制文件夹中并使用imageView.setImageResource(R.id.image); 时,它比以前的方法浏览的图像更大并且更适合屏幕。有没有办法调整图像的大小,使其像往常一样完全适合屏幕。
这是布局文件和java中的代码。
AssetManager manager = getActivity().getAssets();
InputStream input = null;
try {
input = manager.open("images/" + mQuestion.getQImage() + ".png");
} catch (IOException e) {
e.printStackTrace();
}
Bitmap image = BitmapFactory.decodeStream(input);
ImageView qImageView = (ImageView) questionView.findViewById(R.id.ImageView_qImage);
qImageView.setImageBitmap(image);
<ImageView
android:id="@+id/ImageView_qImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/questionTopBottomMargin"
android:background="@color/radioButtonStrokeColor"
android:contentDescription="@string/hello_world"
android:padding="1px"
android:scaleType="fitXY" />
【问题讨论】:
-
drawables 文件夹中是否有该图像的多个 dpi 版本?
-
不,只有一个
-
你试过stackoverflow.com/questions/16749044/…上的建议了吗?