加载网络图片,需要用到Bitmap对象。
加载网络图片有时也需耗时较长时间,所以也应该异步加载。
新建一个外部的ImgLoadTask类(可以更快速加载、提高代码复用性)
1.首先,新建一个Activity,布置其xml代码:
一个按钮Button
一个ImageView加载图片的地方
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"