完成效果:点击保存按钮,布局中的图片存入到SD卡中。点击读取按钮,图片显示到布局下方。
点击获取网络图片按钮,网络图片显示到布局下方。点击保存网络图片按钮,网络图片存入SD卡中。
主布局:
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="com.example.administrator.jreduch09.ImageToSdCardActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/save"
android:text="保存"
android:onClick="saveImg"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/read"
android:text="读取"
android:layout_below="@+id/save"
android:onClick="readImg"
/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/showImg"
android:layout_below="@+id/img"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/httpImg"
android:text="获取网络图片"
android:layout_below="@+id/read"
android:onClick="getUriImg"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/httpSaveImg"
android:text="保存网络图片"
android:layout_below="@+id/httpImg"
android:onClick="saveHttpImg"