首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将多个图像加载到android图像库中?

如何将多个图像加载到android图像库中?
EN

Stack Overflow用户
提问于 2013-12-26 06:08:58
回答 2查看 3.9K关注 0票数 1

我想从一个URL加载成堆的图像到我的画廊。目前,它们存储在可绘制目录中,但我希望从像http://i200.photobucket.com/albums/aa216/example/color.jpg这样的URL链接中加载它们,而不是@ drawable /image1 1

这是我的密码。

main.xml

代码语言:javascript
复制
<?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>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-12-26 06:12:11

阿联酋UniversalImageLoader文库。

以zip的形式下载项目,并在项目中导入库。然后从你的java类中,

代码语言:javascript
复制
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);
票数 1
EN

Stack Overflow用户

发布于 2013-12-26 06:14:42

您可以使用Universal image loader

http://github.com/nostra13/Android-Universal-Image-Loader

代码语言:javascript
复制
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/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20779972

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档