前言:这篇文章用到了Android的handler机制,对于handler机制我也还没搞得太清楚,只能先把相关的几个帖子贴上,大家先看看吧,等后面理解了再仔细讲讲,最后我另外给出了用android原生HttpURLConnection是怎样来下载并显示图片的,但这种方法一般不用,所以我也就不讲了,如果想看就看源码吧
上效果图:
配置AndroidManifest.xml
添加互联网访问权限
XML代码:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
android:id="@+id/btnFirst"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="异步下载方式一" >
android:id="@+id/frameLayout"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp"
android:scaleType="centerInside" >
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_gravity="center" >
一、