【发布时间】:2013-03-19 22:01:15
【问题描述】:
我想有效地加载位图,因为经常在 4.0+ android 上我得到OutOfMemoryError。所以我尝试使用来自 android 开发者页面资源“有效加载位图”的示例代码。
但是我的问题是获取 ImageView 的高度和宽度,因为没有任何常量值来定义尺寸。
开发者页面中包含必填字段的代码。
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
int reqWidth, int reqHeight)
这是我的布局:
<RelativeLayout android:layout_width="match_parent"
android:layout_weight="3"
android:layout_height="0px">
<ImageView
android:id="@+id/img1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:src="@drawable/image" />
我尝试使用image.getHeight(),但没用。
【问题讨论】:
-
应该先搜索 ;) link
-
我不反对先搜索,但该链接并不能解决问题。您有一个
ImageView,您将其宽度和高度设置为wrap_content,意思是“使视图适合图像的大小”,但随后您试图将图像的大小调整为视图......循环逻辑;它行不通。您需要选择尺寸并调整图像大小
标签: android bitmap dimensions