0

I'm trying to create an activity that display an image that is obtained from an url. I want the width of the image to adapt the screen but the height of the image can be longer than the screen so that the image becomes scrollable (vertically). First of all, I displayed the image from a drawable folder and it worked with the following code :

<ScrollView
    android:layout_width="fill_parent"
    android:id="@+id/scrollView1"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:scrollbarAlwaysDrawVerticalTrack="true">
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal">



        <ImageView

            android:src="@drawable/programme"
            android:layout_height="wrap_content"
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:scaleType="fitStart"></ImageView>
    </LinearLayout>
</ScrollView>

I obtained what I wanted : https://i.stack.imgur.com/imPkZ.png

But now I wanted the image to charge from an URL so I used the ion library :

Ion.with(imageView)

            .load("http://...");

The image load but it is no longer scrollable and doesn't display as wanted. http://i.gyazo.com/704324724364235bbe417d5447265c42.png

Do you have any solution? Thanks

Akou
  • 1
  • 3

1 Answers1

0

I found the solution by setting android:layout_width="match_parent" in ScrollView, ImageView and LinearLayout and setting android:adjustViewBounds="true" for ImageView like this :

<ScrollView
    android:layout_width="match_parent"
    android:id="@+id/scrollView1"
    android:layout_height="wrap_content"
    android:scrollbarAlwaysDrawVerticalTrack="true">
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitStart"
            android:adjustViewBounds="true"/>
    </LinearLayout>
</ScrollView>
Akou
  • 1
  • 3