Android异步加载图片详解之方式一(4)

main.xml如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ListView
        android:id="@+id/listView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"/>
    <Button
        android:id="@+id/button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Clear FileCache"/>
</LinearLayout>

listviewitem.xml如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content">
  <ImageView
  	  android:id="@+id/imageView"
	  android:layout_width="50dip"
	  android:layout_height="50dip"
	   android:src="@drawable/stub"
	   android:scaleType="centerCrop"/>
  <TextView
  	  android:id="@+id/textView"
  	  android:layout_width="fill_parent"
	  android:layout_height="wrap_content"
	  android:layout_weight="1"
	  android:layout_gravity="left|center_vertical"
	  android:textSize="20dip"
	  android:layout_marginLeft="10dip"/>
</LinearLayout>

 

时间: 2024-07-29 13:05:45

Android异步加载图片详解之方式一(4)的相关文章

Android异步加载图片详解之方式二(2)

FileCache.java如下: package com.cn.loadImages; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Conte

Android异步加载图片详解之方式一(1)

MainActivity.java如下: package cn.ideallistview; import java.util.ArrayList; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.

Android异步加载图片详解之方式一(2)

FileCache.java如下: package cn.loadImages; import java.io.File; import android.content.Context; import android.net.Uri; import android.os.Environment; public class FileCache { private File fileCacheDir; public FileCache(Context context){ if (Environmen

Android异步加载图片详解之方式一(3)

Utils.java如下: package cn.loadImages; import java.io.InputStream; import java.io.OutputStream; import android.graphics.Bitmap; import android.graphics.BitmapFactory; public class Utils { public static void copyStream(InputStream is, OutputStream os){

Android异步加载图片详解之方式二(3)

main.xml如下: <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" >

Android LayoutInflater加载布局详解及实例代码

Android  LayoutInflater加载布局详解 对于有一定Android开发经验的同学来说,一定使用过LayoutInflater.inflater()来加载布局文件,但并不一定去深究过它的原理,比如 1.LayoutInflater为什么可以加载layout文件? 2.加载layout文件之后,又是怎么变成供我们使用的View的? 3.我们定义View的时候,如果需要在布局中使用,则必须实现带AttributeSet参数的构造方法,这又是为什么呢? 既然在这篇文章提出来,那说明这三

Android 异步加载图片,使用LruCache和SD卡或手机缓存,效果非常的流畅

异步加载图片的例子,网上也比较多,大部分用了HashMap<String, SoftReference<Drawable>> imageCache ,但是现在已经不再推荐使用这种方式了,因为从 Android 2.3 (API Level 9)开始,垃圾回收器会更倾向于回收持有软引用或弱引用的对象,这让软引用和弱引用变得不再可靠.另外,Android 3.0 (API Level 11)中,图片的数据会存储在本地的内存当中,因而无法用一种可预见的方式将其释放,这就有潜在的风险造成应

我的Android进阶之旅------&amp;gt;android异步加载图片显示,并且对图片进行缓存实例

先来看看效果示意图: step1:新建项目DataAsyncLoad,如下图所示 step2:设置应用的UI界面 a.应用的主界面    main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="

实例演示Android异步加载图片(转)

本文给大家演示异步加载图片的分析过程.让大家了解异步加载图片的好处,以及如何更新UI.首先给出main.xml布局文件:简单来说就是 LinearLayout 布局,其下放了2个TextView和5个ImageView. 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout 3 xmlns:android="http://schemas.android.com/apk/res/a