Android Textview 延时加载图片
来源:互联网 发布:冬天保湿面霜推荐 知乎 编辑:程序博客网 时间:2024/05/16 01:20
public class URLImageParser implements Html.ImageGetter {
Context c;
View container;
/***
* Construct the URLImageParser which will execute AsyncTask and refresh the container
* @param t
* @param c
*/
public URLImageParser(View t, Context c) {
this.c = c;
this.container = t;
}
public Drawable getDrawable(String source) {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.add_label_1).copy(Bitmap.Config.ARGB_8888, true);
AnimationDrawable urlDrawable =new AnimationDrawable();
urlDrawable.setBounds(0, 0,400,400);
ImageGetterAsyncTask asyncTask =
new ImageGetterAsyncTask(urlDrawable);
asyncTask.execute(source);
return urlDrawable;
}
public class ImageGetterAsyncTask extends AsyncTask<String, Void, Bitmap> {
AnimationDrawable urlDrawable;
public ImageGetterAsyncTask(AnimationDrawable d) {
this.urlDrawable = d;
}
@Override
protected Bitmap doInBackground(String... params) {
String source = params[0];
return fetchDrawable(source);
}
@Override
protected void onPostExecute(Bitmap bitmap) {
Drawable drawable = new BitmapDrawable(bitmap);
urlDrawable.addFrame(drawable, 1);
urlDrawable.setOneShot(true);
urlDrawable.setBounds(0, 0, 0+bitmap.getWidth(), 0+bitmap.getHeight());
urlDrawable.start();
URLImageParser.this.container.invalidate();
}
/***
* Get the Drawable from URL
* @param urlString
* @return
*/
public Bitmap fetchDrawable(String urlString) {
try {
URL aURL = new URL(urlString);
final URLConnection conn = aURL.openConnection();
conn.connect();
final BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
final Bitmap bm = BitmapFactory.decodeStream(bis);
return bm;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
Context c;
View container;
/***
* Construct the URLImageParser which will execute AsyncTask and refresh the container
* @param t
* @param c
*/
public URLImageParser(View t, Context c) {
this.c = c;
this.container = t;
}
public Drawable getDrawable(String source) {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.add_label_1).copy(Bitmap.Config.ARGB_8888, true);
AnimationDrawable urlDrawable =new AnimationDrawable();
urlDrawable.setBounds(0, 0,400,400);
ImageGetterAsyncTask asyncTask =
new ImageGetterAsyncTask(urlDrawable);
asyncTask.execute(source);
return urlDrawable;
}
public class ImageGetterAsyncTask extends AsyncTask<String, Void, Bitmap> {
AnimationDrawable urlDrawable;
public ImageGetterAsyncTask(AnimationDrawable d) {
this.urlDrawable = d;
}
@Override
protected Bitmap doInBackground(String... params) {
String source = params[0];
return fetchDrawable(source);
}
@Override
protected void onPostExecute(Bitmap bitmap) {
Drawable drawable = new BitmapDrawable(bitmap);
urlDrawable.addFrame(drawable, 1);
urlDrawable.setOneShot(true);
urlDrawable.setBounds(0, 0, 0+bitmap.getWidth(), 0+bitmap.getHeight());
urlDrawable.start();
URLImageParser.this.container.invalidate();
}
/***
* Get the Drawable from URL
* @param urlString
* @return
*/
public Bitmap fetchDrawable(String urlString) {
try {
URL aURL = new URL(urlString);
final URLConnection conn = aURL.openConnection();
conn.connect();
final BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
final Bitmap bm = BitmapFactory.decodeStream(bis);
return bm;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
}
public View getView(final int position, View convertView, ViewGroup parent) {
TextView mtextView = initTextView();
URLImageParser uRLImageParser=new URLImageParser(mtextView, ArticleActivity.this);
mtextView.setText(Html.fromHtml(vo.getContentDetail(),uRLImageParser, null));
}
诶诶 哪个用了的和我说一声啊
转载的注意啦
- Android Textview 延时加载图片
- Android 图片异步加载,延时加载的一些思路
- 图片延时加载
- iOS延时加载图片
- 网页图片延时加载
- 图片延时加载
- Jquery 延时加载图片
- 网站图片延时加载
- 图片延时加载
- Android TextView加载html图片详解
- Android TextView Html加载图片Glide
- android TextView加载html内容并加载图片
- android textView 加载HTML 异步加载网络图片
- android TextView加载html内容并加载图片
- android textView 加载HTML 异步加载网络图片
- js 延时加载 内容 图片
- jquery实现图片延时加载
- jquery lazyload 图片延时加载
- Nhibaernate 在使用Iset<>Invalid Cast错误
- 如何在ashx页面获取Session值
- 【Android进阶】嵌套TabHost (TabHost中放TabHost,类似二级目录、二级树)
- 选择排序法 (Selection Sort)
- event.altKey、event.ctrlKey、event.shiftKey 属性
- Android Textview 延时加载图片
- What:数字信号基带传输的常用码型
- hdu 2438 暴力吧
- 乔纳森·伊夫
- eclipse解决editor does not contain a main type的方法
- httpclient4登录网站
- Notes On <AJAX & PHP> - 1
- netsh
- 动态SQL语句--mysql--mybaits-