缓存网络图片
来源:互联网 发布:麦咖啡软件 编辑:程序博客网 时间:2024/06/15 19:56
<?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:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.bwie.exam013.MainActivity"> <LinearLayout android:id="@+id/ll" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/net_image" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="显示网络图片"/> <Button android:id="@+id/local_image" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="显示缓存图片"/> <Button android:id="@+id/delete" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="清除缓存"/> </LinearLayout> <ImageView android:layout_below="@+id/ll" android:id="@+id/image" android:src="@mipmap/ic_launcher" android:layout_width="match_parent" android:layout_height="match_parent" /></RelativeLayout>
package com.bwie.exam013;import android.os.Bundle;import android.os.Environment;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import android.widget.ImageView;import com.lidroid.xutils.BitmapUtils;import com.lidroid.xutils.cache.FileNameGenerator;public class MainActivity extends AppCompatActivity implements View.OnClickListener { private static final String image_url="http://dl.bizhi.sogou.com/images/2015/02/12/1087025.jpg"; private static final String fileName="cacheFile"; private BitmapUtils bitmapUtils; private String cachePath; private ImageView image; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); cachePath= Environment.getExternalStorageDirectory()+"/cacheFileDir"; bitmapUtils=new BitmapUtils(this,cachePath); bitmapUtils.configDiskCacheFileNameGenerator(new FileNameGenerator() { @Override public String generate(String key) { return fileName; } });} private void initView() { image = (ImageView) findViewById(R.id.image); Button net_image = (Button) findViewById(R.id.net_image); Button local_image = (Button) findViewById(R.id.local_image); Button delete = (Button) findViewById(R.id.delete); net_image.setOnClickListener(this); local_image.setOnClickListener(this); delete.setOnClickListener(this); } public void onClick(View v) { switch (v.getId()){ case R.id.net_image: bitmapUtils.display(image,image_url); break; case R.id.local_image: bitmapUtils.display(image,cachePath+"/"+fileName); break; case R.id.delete: bitmapUtils.getBitmapFileFromDiskCache(cachePath+"/"+fileName).delete(); break; } }}
0 0
- Android网络图片缓存
- Android 网络图片缓存
- 缓存网络图片
- 网络请求图片缓存
- 网络加载图片缓存
- 网络获取图片并缓存
- android 网络图片缓存策略
- android 网络图片双缓存
- IOS网络图片缓存详解
- android 网络图片双缓存
- android 网络图片双缓存
- IOS网络图片缓存详解
- android 网络图片双缓存
- IOS网络图片缓存详解
- android 网络图片双缓存
- android 网络图片双缓存
- android 网络图片双缓存
- android 网络图片双缓存
- Qt动画框架
- VideoView 黑屏
- ListView复用和优化详解
- app从点击到启动
- 线程池
- 缓存网络图片
- Visual Studio中的文件类型(sln vcproj suo user ncb)
- (一)Opencv3.2在Ubuntu14.04下的环境搭建
- 347. Top K Frequent Elements
- 使用lrucache实现图片内存缓存
- 手机无线调试方法
- Linux-网桥原理分析 .
- C++文件流I/O操作:fstream类 完整操作知识点
- 保刚性图像变形算法