【发布时间】:2015-04-03 10:52:58
【问题描述】:
我正在尝试在 Android 的 ImageView 中显示图像,但由于未知原因,某些图像未显示。工作的图像相对较小,而不工作的图像较大(1280x720)左右。我什至尝试通过在 .xml 文件中甚至通过代码添加 maxWidth 或 maxHeight 来限制图像的大小,但仍然没有结果。
这是我的 ImageView 的 .xml 代码;
<ImageView
android:id="@+id/imageImageView"
android:layout_width="fill_parent"
android:maxHeight="100dp"
android:maxWidth="100dp"
android:layout_height="wrap_content"
android:contentDescription="@string/empty"
android:gravity="center"
android:src="@drawable/test3" />
对于我的代码:
ImageView imageView = (ImageView) view
.findViewById(R.id.imageImageView);
imageView.requestLayout();
imageView.getLayoutParams().height = 100;
imageView.getLayoutParams().width = 100;
有什么想法/建议吗?谢谢。
【问题讨论】:
-
不工作怎么办?添加 android:scaleType="centerInside" 看看有没有显示出来。
-
不工作,因为当我尝试插入更大的图像时没有显示任何内容。我将添加该行,看看会发生什么。
-
不,仍然没有显示。
-
如果从 ImageView 中删除 maxHeight 和 maxWidth 属性会发生什么?有用吗?
-
不,这是最初的尝试。我只是添加了这一行,希望它能解决问题,但没有成功。