我想从一个URL加载成堆的图像到我的画廊。目前,它们存储在可绘制目录中,但我希望从像http://i200.photobucket.com/albums/aa216/example/color.jpg这样的URL链接中加载它们,而不是@ drawable /image1 1
这是我的密码。
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ViewFlipper
android:id="@+id/view_flipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>
<TextView
style="@style/ImageTitle"
android:text="@string/image1" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/image2" />
<TextView
style="@style/ImageTitle"
android:text="@string/image2" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/image3" />
<TextView
style="@style/ImageTitle"
android:text="@string/image3" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/image4" />
<TextView
style="@style/ImageTitle"
android:text="@string/image4" />
</RelativeLayout>
</ViewFlipper>
<LinearLayout
style="@style/ButtonContainer"
android:orientation="horizontal" >
<Button
android:id="@+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="@drawable/media_play" />
<Button
android:id="@+id/stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/media_pause" />
</LinearLayout>
<ImageView
android:id="@+id/swipe_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/arrowleft" />
<ImageView
android:id="@+id/swipe_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/arrowright" />
</RelativeLayout>发布于 2013-12-26 06:12:11
阿联酋UniversalImageLoader文库。
以zip的形式下载项目,并在项目中导入库。然后从你的java类中,
ImageView imageView = (ImageView) findViewById(R.id.your_view)
String imageUrl = "your_url";
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(context));
imageLoader.displayImage(imageUrl, imageView);发布于 2013-12-26 06:14:42
您可以使用Universal image loader库
http://github.com/nostra13/Android-Universal-Image-Loader
ImageView imageView = ... // view, where the image will be displayed
String imageUrl = ... // image URL
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(context));
imageLoader.displayImage(imageUrl, imageView);它非常容易使用,并照顾大多数事情,如缓存等。
如果不想使用任何外部库,也可以编写自己的代码来下载和显示图像。
遵循本教程
http://www.androidhive.info/2012/07/android-loading-image-from-url-http/
https://stackoverflow.com/questions/20779972
复制相似问题