android-完整利用AsyncTask实现网络图片下载的实例
先看看效果图:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ? ? android:layout_width="fill_parent" ? ? android:layout_height="fill_parent" ? ? android:orientation="vertical" > ? ? ? <TextView ? ? ? ? android:layout_width="fill_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:text="一步下载图片"? ? ? ? ? android:id="@+id/txt"/> ? ? ? <Button ? ? ? ? android:id="@+id/downImg" ? ? ? ? android:layout_width="wrap_content" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:text="开始下载图片" /> ? ? ? <FrameLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" > ? ? ? ? ? <ImageView ? ? ? ? ? ? android:id="@+id/imgView" ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? android:layout_height="wrap_content" /> ? ? ? ? ? <ProgressBar ? ? ? ? ? ? android:id="@+id/progressBar" ? ? ? ? ? ? android:layout_width="fill_parent" ? ? ? ? ? ? style="?android:attr/progressBarStyleHorizontal" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_gravity="center" ? ? ? ? ? ? android:visibility="invisible" ? ? ? ? ? ? /> ? ? </FrameLayout> </LinearLayout> ? ?