0

Problem

I have a fragment that basically has a scrollview with an image view showed at full screen (look down for layout). If the image loaded for the ImageView is too tall (over 2000 pixel) the result is that the image view will show a blank page.

I am able to scroll down like if the image would be shown.

I started with the original image that is 720x2352 and then I tried cutting parts of the image. At 2000 height pixels the image is correctly shown.

The dimension of the phone where it needs to work is 720x1280.

Code

Layout

<?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>

Question

How can I preserve the height of the image without having the resulted image view to show a blank page?

Phil3992
  • 1,059
  • 6
  • 21
  • 45
Link 88
  • 553
  • 8
  • 27

1 Answers1

1

The pixels you shared is way too huge for system to work. You can simply using An image loading and caching library like Glide, Picasso which helps to resize the image maintaining the aspect ratio like you said.

You can also have this already stack-post as a reference:

Android: Resize a large bitmap file to scaled output file

Community
  • 1
  • 1
Sanjog Shrestha
  • 417
  • 9
  • 16
  • I wanted to keep the images the customer sent to me but at the end I followed your tip and resized the image keeping the aspect ratio with an external program. It worked, thank you – Link 88 Apr 04 '17 at 13:45