【问题标题】:Image in ImageView showing up smaller than expected (Android)ImageView 中的图像显示小于预期(Android)
【发布时间】:2016-07-20 21:39:01
【问题描述】:

我有this animation/code,点击照片会将其放大到全屏,而屏幕的其余部分会变黑。当我使用this banana 库存照片时,尺寸会变得足够大。 然而,当我使用 API 从网上提取图像时,图像变得非常小 我尝试检查图像的大小,但它似乎并不自然那么小。从源下载时,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"
    />

【问题讨论】:

  • 该手机/模拟器的分辨率是多少?如果它是 1920x1080 或类似图像,则图像的尺寸似乎合适......
  • 实际上我用瓶子试过你的ImageView,效果很好。您可以尝试将android:adjustViewBounds="true"android:scaleType="fitXY" 添加到您的ImageView
  • @Salem 我正在运行三星 Galaxy S7(1440 x 2560 像素)
  • @stumped 你可以尝试删除android:scaleType="fitXY" 属性
  • @YasinKaçmaz 感谢帮助!

标签: android image imageview size sizing


【解决方案1】:

只需尝试将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

【讨论】:

  • 它看起来还是一样小
  • 使用了 scaleType 并改变了 finalBounds 偏移的 y 值
  • @stumped 我的朋友我很高兴解决你的问题
【解决方案2】:

如果模拟器/设备尺寸太大,图像看起来很小可能很自然。尽管如此,我可以看到您正在使用android:src="@drawable/bananas1" 从 XML 中静态添加图像,而不是从代码中动态添加图像。如果您想从 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"

【讨论】:

    猜你喜欢
    • 2023-03-31
    • 1970-01-01
    • 2015-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多