问题描述
我正在尝试将图像插入屏幕,但是当我插入一些大图像时,它会出现“位图太大”的错误,而当我插入一个像 400 x 400 像素这样的小图像时,它会变得模糊。 如何选择准确的图像尺寸,使其看起来不错(不模糊)。
这是代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity2">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/non"
android:scaleType="centerCrop">
</ImageView>
解决方法
您可以使用矢量图像,也可以为每个 dpi 使用不同大小的光栅图像。
如果可以,我建议您使用矢量,因为它更简单、更轻便,但如果您不能使用矢量图像,this 会指导您。