ImageView 中的图像显示小于预期 (Android)
Image in ImageView showing up smaller than expected (Android)
我有 this animation/code where a tap on the photo enlarges it to the full screen while the rest of the screen turns black. When I use this banana stock photo the size turns out large enough. However, when I pull images from the web using an API the images turn out very small I tried checking the size of the image and it does not seem to be naturally that small. The water bottle image 从源下载时实际上是 h:89 和 w:273 像素。
//pulling the image and finding its sizes
Glide.with(getContext()).load(currentFood.getImageUrl()).into(ivFullScreen);
int ih=ivFullImage.getMeasuredHeight();//height of imageView = 1440
int iw=ivFullImage.getMeasuredWidth();//width of imageView = 2464
int iH=ivFullImage.getDrawable().getIntrinsicHeight();//original height of underlying image = 3332
int iW=ivFullImage.getDrawable().getIntrinsicWidth();//original width of underlying image = 4442
Toast.makeText(getContext(), "view height: " + ih + " view width: " + iw + " image height: " + iH + " image width: " + iW, Toast.LENGTH_LONG).show();
The Toast showed that the `ivFullImage` size is h:1440 and w:2464 and the image's size is h:3332 and w:4442.
XML:
<LinearLayout android:id="@+id/llFullScreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:alpha="0.0">
</LinearLayout>
<ImageView android:id="@+id/ivFullImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/bananas1"
android:scaleType="centerInside"
android:visibility="invisible"
/>
如果 emulator/device 尺寸太大,图像看起来自然会变小。尽管如此,我可以看到您是从 XML 和 android:src="@drawable/bananas1"
静态添加图像,而不是从代码动态添加图像。如果您想从 Internet 下载图像并添加它,您可以做的是从代码中调用布局的 ImageView,然后从 URL 中获取要添加的图像
ImageView mImage = (ImageView) findViewById(R.id.ivFullImage);
//get the image from the url using the library you have, convert to bitmap
mImage.setImageBitmap(yourImageInBitmap);
此外,在您的 XML 中,您需要定义 ImageView 的宽度和高度以适应您要插入的图像的尺寸,方法是说
android:layout_width="wrap_content"
android:layout_height="wrap_content"
只需尝试将 android:adjustViewBounds="true"
属性添加到您的 ImageView
:
<ImageView android:id="@+id/ivFullImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/bananas1"
android:scaleType="centerInside"
android:adjustViewBounds="true" />
更多信息:ImageView
我有 this animation/code where a tap on the photo enlarges it to the full screen while the rest of the screen turns black. When I use this banana stock photo the size turns out large enough.
//pulling the image and finding its sizes
Glide.with(getContext()).load(currentFood.getImageUrl()).into(ivFullScreen);
int ih=ivFullImage.getMeasuredHeight();//height of imageView = 1440
int iw=ivFullImage.getMeasuredWidth();//width of imageView = 2464
int iH=ivFullImage.getDrawable().getIntrinsicHeight();//original height of underlying image = 3332
int iW=ivFullImage.getDrawable().getIntrinsicWidth();//original width of underlying image = 4442
Toast.makeText(getContext(), "view height: " + ih + " view width: " + iw + " image height: " + iH + " image width: " + iW, Toast.LENGTH_LONG).show();
The Toast showed that the `ivFullImage` size is h:1440 and w:2464 and the image's size is h:3332 and w:4442.
XML:
<LinearLayout android:id="@+id/llFullScreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:alpha="0.0">
</LinearLayout>
<ImageView android:id="@+id/ivFullImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/bananas1"
android:scaleType="centerInside"
android:visibility="invisible"
/>
如果 emulator/device 尺寸太大,图像看起来自然会变小。尽管如此,我可以看到您是从 XML 和 android:src="@drawable/bananas1"
静态添加图像,而不是从代码动态添加图像。如果您想从 Internet 下载图像并添加它,您可以做的是从代码中调用布局的 ImageView,然后从 URL 中获取要添加的图像
ImageView mImage = (ImageView) findViewById(R.id.ivFullImage);
//get the image from the url using the library you have, convert to bitmap
mImage.setImageBitmap(yourImageInBitmap);
此外,在您的 XML 中,您需要定义 ImageView 的宽度和高度以适应您要插入的图像的尺寸,方法是说
android:layout_width="wrap_content"
android:layout_height="wrap_content"
只需尝试将 android:adjustViewBounds="true"
属性添加到您的 ImageView
:
<ImageView android:id="@+id/ivFullImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/bananas1"
android:scaleType="centerInside"
android:adjustViewBounds="true" />
更多信息:ImageView