添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here .

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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>

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. Do you have any solution? Thanks

In your LinearLayout you need width with "match_parent".

Let your "activity_what.xml" like this.

See the demo below.

Thanks for the answer. I didn't copy the full code code but I've already done that and it doesn't seems to work... <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>