渲染图像太高时出错(空白页)
Error when rendering Images too tall (blank page)
问题
我有一个片段,它基本上有一个滚动视图和全屏显示的图像视图(向下看布局)。
如果为 ImageView 加载的图像太高(超过 2000 像素),结果是图像视图将显示空白页。
我可以像显示图片一样向下滚动。
我从 720x2352 的原始图像开始,然后尝试剪切部分图像。在 2000 高度像素处,图像正确显示。
需要工作的phone尺寸是720x1280。
代码
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"/>
</ScrollView>
<!-- other stuff -->
</LinearLayout>
问题
如何在不让生成的图像视图显示空白页的情况下保持图像的高度?
您分享的像素太大,系统无法运行。您可以简单地使用像 Glide、Picasso 这样的图像加载和缓存库,这有助于像您说的那样调整图像大小并保持纵横比。
你也可以把这个已经stack-post作为参考:
Android: Resize a large bitmap file to scaled output file
问题
我有一个片段,它基本上有一个滚动视图和全屏显示的图像视图(向下看布局)。 如果为 ImageView 加载的图像太高(超过 2000 像素),结果是图像视图将显示空白页。
我可以像显示图片一样向下滚动。
我从 720x2352 的原始图像开始,然后尝试剪切部分图像。在 2000 高度像素处,图像正确显示。
需要工作的phone尺寸是720x1280。
代码
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"/>
</ScrollView>
<!-- other stuff -->
</LinearLayout>
问题
如何在不让生成的图像视图显示空白页的情况下保持图像的高度?
您分享的像素太大,系统无法运行。您可以简单地使用像 Glide、Picasso 这样的图像加载和缓存库,这有助于像您说的那样调整图像大小并保持纵横比。
你也可以把这个已经stack-post作为参考:
Android: Resize a large bitmap file to scaled output file