关闭

开源框架 图片下载

标签: 开源框架图片下载android
115人阅读 评论(0) 收藏 举报
分类:


package com.example.image;

import com.bumptech.glide.Glide;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;


public class MainActivity extends Activity {
	
	//将从此URL加载网络图片
	private String image_url = "http://avatar.csdn.net/9/7/A/1_zhangphil.jpg";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		ListView lv = (ListView) findViewById(R.id.listView);
		lv.setAdapter(new MyAdapter(this,R.layout.item));
	}
	
	private class MyAdapter extends ArrayAdapter<String>{
		
		private int resource;
		
		public MyAdapter(Context context, int resource) {
			super(context, resource);
			this.resource=resource;
			
		}

		@Override
		public int getCount() {
			
			return 100;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			if(convertView == null)
				convertView = LayoutInflater.from(getApplication()).inflate(resource, null);
			
			ImageView iv = (ImageView) convertView.findViewById(R.id.imageView);  
            TextView text=(TextView) convertView.findViewById(R.id.textView);
            text.setText(position+"");
			
            //开源框架 调用libs.glide-3.6.1.jar
            Glide.with(getApplication()).load(image_url).crossFade(1000).into(iv); 
			
			return convertView;
		}

	}
	
}

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.image.MainActivity" >

    <ListView  
        android:id="@+id/listView"  
        android:layout_width="match_parent"  
        android:layout_height="wrap_content" >  
    </ListView>  


</RelativeLayout>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <ImageView  
        android:id="@+id/imageView"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:22835次
    • 积分:1135
    • 等级:
    • 排名:千里之外
    • 原创:91篇
    • 转载:20篇
    • 译文:0篇
    • 评论:1条
    文章分类
    文章存档
    最新评论