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
akou
831 PointsDisplay a scrollable image from a url in android studio
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
3 Answers
Luiz Carlos
15,714 PointsIn your LinearLayout you need width with "match_parent".
Let your "activity_what.xml" like this.
See the demo below.
Luiz Carlos
15,714 PointsCreate a "ScrollView" in you xml and put your "LinearLayout" with you "ImageView" inside "ScrollView".
akou
831 PointsThanks 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>
Luiz Carlos
15,714 PointsShare your project in github that i'm going to see it.
akou
831 PointsThanks here it is : https://github.com/akouu/Open/

akou
831 Pointsakou
831 PointsThank you so much! By the way how did you do the gif ?