有可扩展的图像网址,我想自动调整到我正在使用的图像视图中。这是我的图像视图代码
<com.livetalkback.xfactor2012.ui.views.CmsRemoteImageView
android:id="@+id/categoryThumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="4dp"
android:src="@drawable/ic_category_thumb_default" />
如果附加具有所需高度和宽度的URL,则其自动调整 但我不想附加硬编码高度和宽度,因为我的应用程序支持多种屏幕尺寸的设备。请帮忙
您可以尝试在onCreate(bundle savedInstanceState)
中按 id 查找 imageView,并将其源设置为 yourWebServiceQueryResult
,以便能够使用 eponym 方法将其解码为样本大小。
再见
我假设您的自定义图像视图正在扩展典型的Android图像视图。在这种情况下,可以使用缩放类型作为 Fitxy 属性。
更多信息。
我认为您是否正在获取图像并设置为给定的视图,您可以使用查找图像的默认宽度和高度,然后找到它们的纵横比以及您希望缩放的比例您可以通过矩阵调整其大小
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth / width, scaleHeight / height);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
bm.recycle();
return resizedBitmap;