gpt4 book ai didi

android - 在 Android 中使用 PhotoView 显示最初的完整图像

转载 作者:太空宇宙 更新时间:2023-11-03 13:46:42 25 4
gpt4 key购买 nike

我正在开发一个 Android 应用程序。在我的应用程序中,我需要像 Facebook 中那样的缩放图像功能。所以,我使用了这个库 - https://github.com/chrisbanes/PhotoView .但是我在首次加载图像时无法显示完整图像。

这就是我将 PhotoViewAttacher 设置为 ImageView 的方式

    photoViewAttacher = new PhotoViewAttacher(imageView);
photoViewAttacher.setZoomable(true);
photoViewAttacher.update();

这是imageview的xml布局

      <ImageView

android:id="@+id/item_details_image"
android:scaleType="fitCenter"
android:layout_width="match_parent"
android:layout_height="match_parent" />

我想做的是,如果图像大于屏幕尺寸,我希望图像显示适合屏幕。不管它有多大。但图像可以小于屏幕尺寸。我只想在最初显示完整图像。但是上面的代码给了我这个结果。

enter image description here

如您在屏幕截图中所见,它无法显示整个图像。它只显示部分。如果我想查看图像的其他区域,我想滚动或滑动,因为图像最初不适合屏幕。所以我尝试更改 XML 以最初显示图像的整个区域。这是我更改为的 XML。

<ImageView

android:id="@+id/item_details_image"
android:scaleType="centerInside"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

如您所见,我将高度从 match_parent 更改为 wrap_content。规模类型也是如此。当我更改为它时,它最初会像这样显示完整图像。

enter image description here

它显示完整图像但较小。对我来说完全没问题。这就是我想要的。问题在于缩放功能。当我放大时,图像不能大于图像高度。请参见下面的屏幕截图。

enter image description here

正如您在上面看到的,当我放大时它没有显示完整图像。 ImageView 高度没有变化。

最佳答案

 <ImageView
android:id="@+id/item_details_image"
android:scaleType="fitCenter"
android:layout_width="match_parent"
android:layout_height="match_parent" />

您需要ma​​tch_parent 高度或宽度

关于android - 在 Android 中使用 PhotoView 显示最初的完整图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40903953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com