今天2018年2月6日新浪2020年1月3日微博热搜系统故障了吗?

蜂鸟手机端
焦圈,为摄影而生
切换到宽屏
浏览(1915)│回复(12)
蜂鸟网用户等级和积分规则改版啦!
积分换礼活动已开启,您可以用积分兑换礼品,详情请点击:
佳能5Dlll和索尼a7ll的选择
想进一台机子,在5DIII和a7II之间选择,请大神吗指点一下,谢谢了!
引用无信仰无爱好发表于1楼的内容
不差钱就进a7ii,索尼的头绝对牛笔。
引用nmgcgl0121发表于2楼的内容
不差钱就进5Dlll,佳能镜头处理无忧
引用天山路客发表于3楼的内容
不差钱就买买买,取长补短,和百家之长为正道。
咦,楼主你逗我们呢?
引用没空钓鱼发表于4楼的内容
有钱就索尼!
引用不会拍照555发表于5楼的内容
无论品牌影响力还是使用功能,都不是同一档次的。
引用拉灯睡觉发表于6楼的内容
不折腾选佳能,器材党入sony
引用koylu8074发表于7楼的内容
作者: 无信仰无爱好想进一台机子,在5DIII和a7II之间选择,请大神吗指点一下,谢谢了!
不在乎相机的体积重量,首选5D3。
引用巫师008发表于8楼的内容
mb4转接环,佳能镜头成大法副厂头引用:
作者: 天山路客不差钱就进5Dlll,佳能镜头处理无忧
引用平行线的交点发表于9楼的内容
5D3用着挺舒服的,色彩和功能非常好用,如果可以降价,还想再买个
引用LBYY9发表于10楼的内容
佳能5Dlll和索尼a7ll的选择
焦圈,为摄影而生
您可以发表新主题
您可以回复主题
您可以上传附件
您可以编辑您的帖子
论坛启用HTML代码仿微信图片选择器
实现该功能的重要组成部分有:利用gridview加载本地图片,gridView控件的使用,Intent之间数据的传递,和利用ContentProvider获取图片,和PopupWindow弹出页面的使用,利用Bitmap解决OOM问题。
仿微信图片选择器
下载连接:
先上图,后上代码:
打开app后点击添加图片按钮:
获取选择的图片 并返回在gridview中:
实现该功能的重要组成部分有:利用gridview加载本地图片,gridView控件的使用,Intent之间数据的传递,和利用ContentProvider获取图片,和PZ喎"/kf/ware/vc/" target="_blank" class="keylink">vcHVwV2luZG93ta+z9tKzw+a1xMq508OjrMD708NCaXRtYXC94r72T09NzsrM4qGjPC9wPg0KPHA+z8LD5r+qyrzM+bP2tPrC66O6PGJyIC8+DQpNYWluQWN0aXZpdHnOxLz+tcS0+sLryOfPwqO6PGJyIC8+DQpgaW1wb3J0IGphdmEudXRpbC5BcnJheUxpc3Q7PGJyIC8+DQppbXBvcnQgamF2YS51dGlsLkhhc2hNYXA7PGJyIC8+DQppbXBvcnQgamF2YS51dGlsLkxpc3Q7PC9wPg0KPHA+aW1wb3J0IGFuZHJvaWQuYXBwLkFjdGl2aXR5OzxiciAvPg0KaW1wb3J0IGFuZHJvaWQuY29udGVudC5JbnRlbnQ7PGJyIC8+DQppbXBvcnQgYW5kcm9pZC5ncmFwaGljcy5CaXRtYXA7PGJyIC8+DQppbXBvcnQgYW5kcm9pZC5ncmFwaGljcy5CaXRtYXBGYWN0b3J5OzxiciAvPg0KaW1wb3J0IGFuZHJvaWQub3MuQnVuZGxlOzxiciAvPg0KaW1wb3J0IGFuZHJvaWQudXRpbC5Mb2c7PGJyIC8+DQppbXBvcnQgYW5kcm9pZC52aWV3LlZpZXc7PGJyIC8+DQppbXBvcnQgYW5kcm9pZC52aWV3LldpbmRvdzs8YnIgLz4NCmltcG9ydCBhbmRyb2lkLndpZGdldC5CdXR0b247PGJyIC8+DQppbXBvcnQgYW5kcm9pZC53aWRnZXQuRWRpdFRleHQ7PGJyIC8+DQppbXBvcnQgYW5kcm9pZC53aWRnZXQuR3JpZFZpZXc7PGJyIC8+DQppbXBvcnQgYW5kcm9pZC53aWRnZXQuSW1hZ2VCdXR0b247PGJyIC8+DQppbXBvcnQgYW5kcm9pZC53aWRnZXQuSW1hZ2VWaWV3OzxiciAvPg0KaW1wb3J0IGFuZHJvaWQud2lkZ2V0LlNpbXBsZUFkYXB0ZXI7PGJyIC8+DQppbXBvcnQgYW5kcm9pZC53aWRnZXQuU2ltcGxlQWRhcHRlci5WaWV3QmluZGVyOzxiciAvPg0KaW1wb3J0IGFuZHJvaWQud2lkZ2V0LlRvYXN0OzwvcD4NCjxwPnB1YmxpYyBjbGFzcyBNYWluQWN0aXZpdHkgZXh0ZW5kcyBBY3Rpdml0eSB7PC9wPg0KPHByZSBjbGFzcz0="brush:">
private ImageButton imageButton_poprecommend_
private Button button_poprecommend_
private EditText editText_
private ImageButton imageButton_poprecommend_
private GridView gridView_
private PopRecommend_ImageAdd_Adapter imageA
private ArrayList shuju = new ArrayList();
public static MainA
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
activity =
shuju = new ArrayList();
Intent intent = this.getIntent();
shuju = intent.getStringArrayListExtra("shuju");
if (shuju != null) {
imageAdapter = new PopRecommend_ImageAdd_Adapter(this, shuju);
gridView_poprecommend.setAdapter(imageAdapter);
private void FindId() {
imageButton_poprecommend_back = (ImageButton) findViewById(R.id.imagview_poprecommend_back);
button_poprecommend_fabu = (Button) findViewById(R.id.button_poprecommend_fabu);
editText_poprecommend = (EditText) findViewById(R.id.edittext_poprecommend);
imageButton_poprecommend_tianjia = (ImageButton) findViewById(R.id.iamgebutton_poprecommend_tianjiatupian);
gridView_poprecommend = (GridView)this.findViewById(R.id.gridview_poprecommend);
private void Dianji() {
imageButton_poprecommend_back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (Activity_Image_Add.imageAdd!=null)
Activity_Image_Add.imageAdd.finish();
button_poprecommend_fabu.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (Activity_Image_Add.imageAdd!=null)
Activity_Image_Add.imageAdd.finish();
if (editText_poprecommend.getText().toString().equals("")) {
Toast.makeText(getApplication(), "发布内容不能为空", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplication(), "发布成功", Toast.LENGTH_SHORT).show();
imageButton_poprecommend_tianjia.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(getApplication(), Activity_Image_Add.class);
startActivity(intent);
Activity_Image_Add activity的页面代码:
package com.xiyouliwp.
import java.io.F
import java.io.FilenameF
import java.util.ArrayL
import java.util.A
import java.util.HashS
import java.util.LinkedL
import java.util.L
import android.app.A
import android.app.ProgressD
import android.content.ContentR
import android.content.C
import android.content.I
import android.database.C
import android.graphics.C
import android.net.U
import android.os.B
import android.os.E
import android.os.H
import android.os.M
import android.provider.MediaS
import android.util.DisplayM
import android.util.L
import android.view.G
import android.view.KeyE
import android.view.LayoutI
import android.view.V
import android.view.W
import android.view.WindowM
import android.widget.GridV
import android.widget.ImageB
import android.widget.ImageV
import android.widget.LinearL
import android.widget.PopupW
import android.widget.RelativeL
import android.widget.TextV
import android.widget.T
* 需求:IPet的图片选择器,
* Created by lwp940118 on .
public class Activity_Image_Add extends Activity implements List_File_PopWind.OnImageDirSelected {
private ImageButton imageButton_ImageAdd_
private ImageButton imageButton_ImageAdd_
private GridView gridView_ImageA
int totalCount = 0;
* 存储文件夹中的图片数量
private int mPicSize = 0;
* 图片数量最多的文件夹
private File maxImageF
private RelativeLayout relativeLayout_
* 所以图片
private List mI
* list存放扫描到的文件夹的信息
private List imageFolders = new ArrayList();
基于hashmap实现的,利用他可以防止一个文件夹
private HashSet mImagePath = new HashSet();
//弹出对话框
private ProgressDialog mprogressD
private TextView textview_ChooseD
private TextView textview_ImageC
//定义屏幕的高度
private int screenHeight = 0;
* 用户选择的图片,存储为图片的完整路径
public static List mSelectedImage = new LinkedList();
private ArrayList
private MyAdapter myA
private List_File_PopWind popW
public static Activity_Image_Add imageA
private Handler handler = new Handler() {
public void handleMessage(Message msg) {
//加载的那个对话框
mprogressDialog.dismiss();
//view绑定数据
dateView();
//初始化Popwind
initPopWind();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_add);
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
screenHeight = displayMetrics.heightP
Log.e("screenHeight----&", "" + screenHeight);
imageAdd =
kongJianSheZhi();
getImages();
initEvent();
// 返回按键调用
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (MainActivity.activity!=null)
MainActivity.activity.finish();
shuju = new ArrayList();
for (int i = 0; i & mSelectedImage.size(); i++)
shuju.add(mSelectedImage.get(i));
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
intent.putStringArrayListExtra("shuju",shuju);
startActivity(intent);
* 弹出popwind
private void initEvent() {
relativeLayout_popwind.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
popWind.setAnimationStyle(R.style.AnimBottom);
popWind.showAtLocation(Activity_Image_Add.this.findViewById(R.id.imagebutton_imageadd_back),
Gravity.BOTTOM, 0, 0);
// 设置背景颜色变暗
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = 0.3f;
getWindow().setAttributes(lp);
* 绑定view的数据
private void dateView() {
if (maxImageFile == null) {
Toast.makeText(getApplicationContext(), "没有扫描到图片", Toast.LENGTH_SHORT).show();
连接列表与数组,当一个更新时 另一个也自动更新但是没有add
和remove方法
mImags = Arrays.asList(maxImageFile.list());
myAdapter = new MyAdapter(getApplicationContext(), mImags, R.layout.item_gridview_imageadd,
maxImageFile.getAbsolutePath());
gridView_ImageAdd.setAdapter(myAdapter);
//显示多少张图片 在popwind中
textview_ImageCount.setText(totalCount + "张");
* 初始化popwind的弹出界面
private void initPopWind() {
popWind = new List_File_PopWind(LinearLayout.LayoutParams.MATCH_PARENT, (int) (screenHeight
* 0.7), imageFolders, LayoutInflater.from(getApplicationContext())
.inflate(R.layout.list_dir, null));
popWind.setOnDismissListener(new PopupWindow.OnDismissListener() {
public void onDismiss() {
// 设置背景颜色变暗
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = 1.0f;
getWindow().setAttributes(lp);
//设置文件夹的回调
popWind.setOnImageDirSelected(this);
* 利用contentProvider扫描手机中的图片,并获取jpn最多的那个文件夹
* ContentProvider
为四大,详情见我的博客
* Android四大组件介绍http://blog.csdn.net/qq_/article/details/
private void getImages() {
//判断Sd卡的状态 是否可用
if (!Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
Toast.makeText(getApplicationContext(), "没有找到SD", Toast.LENGTH_SHORT).show();
//显示进度条
mprogressDialog = ProgressDialog.show(this, null, "图片读取中...");
new Thread(new Runnable() {
public void run() {
//读取第一张图片
String firstImagePath =
//EXTERNAL_CONTENT_URI多选
Uri mImageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
//ContentResolver应用之间数据共享
ContentResolver mResolver = Activity_Image_Add.this.getContentResolver();
//数据查找,找出JPEG和png格式的图片,,,MediaStore为Android手机的多媒体
Cursor mCursor = mResolver.query(mImageUri, null, MediaStore.Images.Media.MIME_TYPE + "=? or "
+ MediaStore.Images.Media.MIME_TYPE + "=?",
new String[]{"image/jpeg", "image/png"}, MediaStore.Images.Media.DATE_MODIFIED);
//读取图片
while (mCursor.moveToNext()) {
//定义图片的路径
String imagePath = mCursor.getString(mCursor.getColumnIndex
(MediaStore.Images.Media.DATA));
//获取第一张图片的路径
if (firstImagePath == null)
firstImagePath = imageP
//获取该图片的父路径名
File parentFile = new File(imagePath).getParentFile();
if (parentFile == null)
String folderPath = parentFile.getAbsolutePath();
ImageFolder imageFolder =
//利用hashset防止一个文件夹被多次扫描
if (mImagePath.contains(folderPath)) {
mImagePath.add(folderPath);
ImageFolder
imageFolder = new ImageFolder();
imageFolder.setFolderPath(folderPath);
imageFolder.setFirstImagePath(imagePath);
int picSize = parentFile.list(new FilenameFilter() {
public boolean accept(File dir, String filename) {
if (filename.endsWith(".png") || filename.endsWith(".jpg")
|| filename.endsWith(".jpeg"))
totalCount += picS
imageFolder.setImageCount(picSize);
imageFolders.add(imageFolder);
//更新最大数量文件夹
if (picSize & mPicSize) {
mPicSize = picS
maxImageFile = parentF
mCursor.close();
//扫描完成
hashset释放
mImagePath =
线程Handler
图片扫秒完成
handler.sendEmptyMessage(0x110);
}).start();
private void findId() {
gridView_ImageAdd = (GridView) findViewById(R.id.gridview_imageadd);
imageButton_ImageAdd_back = (ImageButton) findViewById(R.id.imagebutton_imageadd_back);
imageButton_ImageAdd_finish = (ImageButton) findViewById(R.id.imagebutton_imageadd_finish);
textview_ChooseDir = (TextView) findViewById(R.id.id_choose_dir);
textview_ImageCount = (TextView) findViewById(R.id.id_total_count);
relativeLayout_popwind = (RelativeLayout) findViewById(R.id.id_bottom_ly);
private void kongJianSheZhi() {
imageButton_ImageAdd_finish.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.e("完成---&","完成");
if (MainActivity.activity!=null)
MainActivity.activity.finish();
shuju = new ArrayList();
for (int i = 0; i & mSelectedImage.size(); i++)
shuju.add(mSelectedImage.get(i));
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
intent.putStringArrayListExtra("shuju",shuju);
startActivity(intent);
imageButton_ImageAdd_back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
public void selected(ImageFolder floder) {
maxImageFile = new File(floder.getFolderPath());
mImags = Arrays.asList(maxImageFile.list(new FilenameFilter() {
public boolean accept(File dir, String filename) {
if (filename.endsWith(".jpg") || filename.endsWith(".png")
|| filename.endsWith(".jpeg"))
* 可以看到文件夹的路径和图片的路径分开保存,极大的减少了内存的消耗;
myAdapter = new MyAdapter(getApplicationContext(), mImags,
R.layout.item_gridview_imageadd, maxImageFile.getAbsolutePath());
gridView_ImageAdd.setAdapter(myAdapter);
// mAdapter.notifyDataSetChanged();
textview_ImageCount.setText(floder.getImageCount() + "张");
textview_ChooseDir.setText(floder.getFolderName());
popWind.dismiss();
* gridview的定义适配器
public class MyAdapter extends CommonAdapter {
* 文件夹路径
private String mDirP
public MyAdapter(Context context, List mDatas, int itemLayoutId,
String dirPath) {
super(context, mDatas, itemLayoutId);
this.mDirPath = dirP
public void convert(final ViewHolder helper, final String item) {
//设置no_pic
helper.setImageResource(R.id.id_item_image, R.drawable.pictures_no);
//设置no_selected
helper.setImageResource(R.id.id_item_select,
R.drawable.picture_unselected);
//设置图片
helper.setImageByUrl(R.id.id_item_image, mDirPath + "/" + item);
final ImageView mImageView = helper.getView(R.id.id_item_image);
final ImageView mSelect = helper.getView(R.id.id_item_select);
mImageView.setColorFilter(null);
//设置ImageView的点击事件
mImageView.setOnClickListener(new View.OnClickListener() {
//选择,则将图片变暗,反之则反之
public void onClick(View v) {
// 已经选择过该图片
if (mSelectedImage.contains(mDirPath + "/" + item)) {
mSelectedImage.remove(mDirPath + "/" + item);
mSelect.setImageResource(R.drawable.picture_unselected);
mImageView.setColorFilter(null);
} else {// 未选择该图片
mSelectedImage.add(mDirPath + "/" + item);
mSelect.setImageResource(R.drawable.pictures_selected);
mImageView.setColorFilter(Color.parseColor("#"));
* 已经选择过的图片,显示出选择过的效果
if (mSelectedImage.contains(mDirPath + "/" + item)) {
mSelect.setImageResource(R.drawable.pictures_selected);
mImageView.setColorFilter(Color.parseColor("#"));
BitmapUtilities问价:用于缩小图片的尺寸,避免OOM问题出现
package com.xiyouliwp.
* Created by lwp940118 on .
import android.graphics.B
import android.graphics.BitmapF
import android.graphics.M
public class BitmapUtilities {
public BitmapUtilities() {
// TODO Auto-generated constructor stub
public static Bitmap getBitmapThumbnail(String path,int width,int height){
Bitmap bitmap =
//这里可以按比例缩小图片:
/*BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = 4;//宽和高都是原来的1/4
bitmap = BitmapFactory.decodeFile(path, opts); */
/*进一步的,
如何设置恰当的inSampleSize是解决该问题的关键之一。BitmapFactory.Options提供了另一个成员inJustDecodeBounds。
设置inJustDecodeBounds为true后,decodeFile并不分配空间,但可计算出原始图片的长度和宽度,即opts.width和opts.height。
有了这两个参数,再通过一定的算法,即可得到一个恰当的inSampleSize。*/
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds =
BitmapFactory.decodeFile(path, opts);
opts.inSampleSize = Math.max((int)(opts.outHeight / (float) height), (int)(opts.outWidth / (float) width));
opts.inJustDecodeBounds =
bitmap = BitmapFactory.decodeFile(path, opts);
public static Bitmap getBitmapThumbnail(Bitmap bmp,int width,int height){
Bitmap bitmap =
if(bmp != null ){
int bmpWidth = bmp.getWidth();
int bmpHeight = bmp.getHeight();
if(width != 0 && height !=0){
Matrix matrix = new Matrix();
float scaleWidth = ((float) width / bmpWidth);
float scaleHeight = ((float) height / bmpHeight);
matrix.postScale(scaleWidth, scaleHeight);
bitmap = Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeight, matrix, true);
CommonAdapter文件:超级适配器,也成通配器,可以使用gridview和listview共同使用:
package com.xiyouliwp.
import java.util.L
import android.content.C
import android.view.LayoutI
import android.view.V
import android.view.ViewG
import android.widget.BaseA
* 通配器,CommonAdapter通过封装BaseAdapter和RecyclerView.Adapter得到通用的、简单易用的Adapter。
* 作为ListView和GridView的通用适配器。
* 超级适配器
public abstract class CommonAdapter extends BaseAdapter {
protected LayoutInflater mI
protected Context mC
protected List mD
protected final int mItemLayoutId;
public CommonAdapter(Context context, List mDatas, int itemLayoutId) {
this.mContext =
this.mInflater = LayoutInflater.from(mContext);
this.mDatas = mD
this.mItemLayoutId = itemLayoutId;
public int getCount() {
return mDatas.size();
public T getItem(int position) {
return mDatas.get(position);
public long getItemId(int position) {
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder viewHolder = getViewHolder(position, convertView,
convert(viewHolder, getItem(position));
return viewHolder.getConvertView();
public abstract void convert(ViewHolder helper, T item);
private ViewHolder getViewHolder(int position, View convertView,
ViewGroup parent) {
return ViewHolder.get(mContext, convertView, parent, mItemLayoutId,
position);
DiskLruCache文件:点击获取到的图片的path路径进行解析
package com.xiyouliwp.
* Created by lwp940118 on .
import java.io.BufferedOutputS
import java.io.F
import java.io.FileNotFoundE
import java.io.FileOutputS
import java.io.FilenameF
import java.io.IOE
import java.io.OutputS
import java.io.UnsupportedEncodingE
import java.net.URLE
import java.util.C
import java.util.LinkedHashM
import java.util.M
import java.util.Map.E
import android.content.C
import android.graphics.B
import android.pressF
import android.graphics.BitmapF
public class DiskLruCache {
private static final String CACHE_FILENAME_PREFIX = "cache_";
private static final int MAX_REMOVALS = 4;
private static final int INITIAL_CAPACITY = 32;
private static final float LOAD_FACTOR = 0.75f;
private final File mCacheD
private int cacheSize = 0;
private int cacheByteSize = 0;
private final int maxCacheItemSize = 64; // 64 item default
private long maxCacheByteSize = 1024 * 1024 * 5; // 5MB default
private CompressFormat mCompressFormat = CompressFormat.JPEG;
private int mCompressQuality = 70;
private final int IO_BUFFER_SIZE = 4 * 1024;
private final Map mLinkedHashMap = Collections.synchronizedMap(new LinkedHashMap(INITIAL_CAPACITY, LOAD_FACTOR, true));
* A filename filter to use to identify the cache filenames which have CACHE_FILENAME_PREFIX prepended.
private static final FilenameFilter cacheFileFilter = new FilenameFilter() {
public boolean accept(File dir, String filename) {
return filename.startsWith(CACHE_FILENAME_PREFIX);
* Used to fetch an instance of DiskLruCache.
* @param context
* @param cacheDir
* @param maxByteSize
public static DiskLruCache openCache(Context context, File cacheDir, long maxByteSize) {
if (!cacheDir.exists()) {
cacheDir.mkdir();
if (cacheDir.isDirectory() && cacheDir.canWrite()) {
return new DiskLruCache(cacheDir, maxByteSize);
* @param cacheDir
* @param maxByteSize
private DiskLruCache(File cacheDir, long maxByteSize) {
mCacheDir = cacheD
maxCacheByteSize = maxByteS
* Add a bitmap to the disk cache.
* @param key
A unique identifier for the bitmap.
* @param data The bitmap to store.
public void put(String key, Bitmap data) {
synchronized (mLinkedHashMap) {
if (mLinkedHashMap.get(key) == null) {
final String file = createFilePath(mCacheDir, key);
if (writeBitmapToFile(data, file)) {
put(key, file);
flushCache();
} catch (final FileNotFoundException e) {
} catch (final IOException e) {
private void put(String key, String file) {
mLinkedHashMap.put(key, file);
cacheSize = mLinkedHashMap.size();
cacheByteSize += new File(file).length();
* Flush the cache, removing oldest entries if the total size is over the specified cache size. Note that this isn't keeping track of stale files in the cache directory that
* aren't in the HashMap. If the images and keys in the disk cache change often then they probably won't ever be removed.
private void flushCache() {
Entry eldestE
File eldestF
long eldestFileS
int count = 0;
while (count & MAX_REMOVALS && (cacheSize & maxCacheItemSize || cacheByteSize & maxCacheByteSize)) {
eldestEntry = mLinkedHashMap.entrySet().iterator().next();
eldestFile = new File(eldestEntry.getValue());
eldestFileSize = eldestFile.length();
mLinkedHashMap.remove(eldestEntry.getKey());
eldestFile.delete();
cacheSize = mLinkedHashMap.size();
cacheByteSize -= eldestFileS
* Get an image from the disk cache.
* @param key The unique identifier for the bitmap
* @return The bitmap or null if not found
public Bitmap get(String key) {
synchronized (mLinkedHashMap) {
final String file = mLinkedHashMap.get(key);
if (file != null) {
return BitmapFactory.decodeFile(file);
final String existingFile = createFilePath(mCacheDir, key);
if (new File(existingFile).exists()) {
put(key, existingFile);
return BitmapFactory.decodeFile(existingFile);
} catch (OutOfMemoryError e) {
* Checks if a specific key exist in the cache.
* @param key The unique identifier for the bitmap
* @return true if found, false otherwise
public boolean containsKey(String key) {
// See if the key is in our HashMap
if (mLinkedHashMap.containsKey(key)) {
// Now check if there's an actual file that exists based on the key
final String existingFile = createFilePath(mCacheDir, key);
if (new File(existingFile).exists()) {
// File found, add it to the HashMap for future use
put(key, existingFile);
* Removes all disk cache entries from this instance cache dir
public void clearCache() {
DiskLruCache.clearCache(mCacheDir);
* Removes all disk cache entries from the application cache directory in the uniqueName sub-directory.
* @param context
The context to use
* @param uniqueName A unique cache directory name to append to the app cache directory
public static void clearCache(Context context, String uniqueName) {
File cacheDir = getDiskCacheDir(context, uniqueName);
clearCache(cacheDir);
* Removes all disk cache entries from the given directory. This should not be called directly, call {@link DiskLruCache#clearCache(Context, String)} or
* {@link DiskLruCache#clearCache()} instead.
* @param cacheDir The directory to remove the cache files from
private static void clearCache(File cacheDir) {
final File[] files = cacheDir.listFiles(cacheFileFilter);
for (int i = 0; i & files. i++) {
files[i].delete();
* Get a usable cache directory (external if available, internal otherwise).
* @param context
The context to use
* @param uniqueName A unique directory name to append to the cache dir
* @return The cache dir
public static File getDiskCacheDir(Context context, String uniqueName) {
// Check if media is mounted or storage is built-in, if so, try and use external cache dir
// otherwise use internal cache dir
final String cachePath = context.getCacheDir().getPath();
return new File(cachePath + File.separator + uniqueName);
* Creates a constant cache file path given a target cache directory and an image key.
* @param cacheDir
* @param key
public static String createFilePath(File cacheDir, String key) {
// Use URLEncoder to ensure we have a valid filename, a tad hacky but it will do for
// this example
return cacheDir.getAbsolutePath() + File.separator + CACHE_FILENAME_PREFIX + URLEncoder.encode(key.replace("*", ""), "UTF-8");
} catch (final UnsupportedEncodingException e) {
* Create a constant cache file path using the current cache directory and an image key.
* @param key
public String createFilePath(String key) {
return createFilePath(mCacheDir, key);
* Sets the target compression format and quality for images written to the disk cache.
* @param compressFormat
* @param quality
public void setCompressParams(CompressFormat compressFormat, int quality) {
mCompressFormat = compressF
mCompressQuality =
* Writes a bitmap to a file. Call {@link DiskLruCache#setCompressParams(CompressFormat, int)} first to set the target bitmap compression and format.
* @param bitmap
* @param file
private boolean writeBitmapToFile(Bitmap bitmap, String file) throws IOException, FileNotFoundException {
OutputStream out =
out = new BufferedOutputStream(new FileOutputStream(file), IO_BUFFER_SIZE);
press(mCompressFormat, mCompressQuality, out);
} finally {
if (out != null) {
out.close();
ImageFolder文件:图片的信息的定义:
package com.xiyouliwp.
* 需求:对手机中的图片进行扫描,直接显示在gridview上,并且在扫描结束后得到一个list,,list里面存的是所有包含
* 图片的文件夹
* Created by lwp940118 on .
public class ImageFolder {
//文件夹的路径
private String folderP
//第一张图片的文件夹路径
private String firstImageP
//文件夹名称
private String folderN
//图片的数量
private int imageCount = 0;
public int getImageCount() {
return imageC
public String getFirstImagePath() {
return firstImageP
public String getFolderName() {
return folderN
public String getFolderPath() {
return folderP
public void setFirstImagePath(String firstImagePath) {
this.firstImagePath = firstImageP
public void setFolderPath(String folderPath) {
this.folderPath = folderP
//判断字符/它第一次出现的位置
int start = this.folderPath.lastIndexOf("/");
//得到从/第一次出现的位置开始
到该字符串结束的子串为folderName
this.folderName = this.folderPath.substring(start);
public void setImageCount(int imageCount) {
this.imageCount = imageC
ImageLoade文件:缓存图片,使grideview运行流畅
package com.xiyouliwp.
import java.lang.reflect.F
import java.util.LinkedL
import java.util.concurrent.ExecutorS
import java.util.concurrent.E
import java.util.concurrent.S
import android.graphics.B
import android.graphics.BitmapF
import android.os.H
import android.os.L
import android.os.M
import android.support.v4.util.LruC
import android.util.DisplayM
import android.util.L
import android.view.ViewGroup.LayoutP
import android.widget.ImageV
public class ImageLoade {
* 图片缓存的核心类
private LruCache mLruC
private ExecutorService mThreadP
* 线程池的线程数量,默认为1
private int mThreadCount = 1;
* 队列的调度方式
private Type mType = Type.LIFO;
* 任务队列
private LinkedList mT
* 轮询的线程
private Thread mPoolT
private Handler mPoolThreadH
* 运行在UI线程的handler,用于给ImageView设置图片
private Handler mH
* 引入一个值为1的信号量,防止mPoolThreadHander未初始化完成
private volatile Semaphore mSemaphore = new Semaphore(0);
* 引入一个值为1的信号量,由于线程池内部也有一个阻塞线程,防止加入任务的速度过快,使LIFO效果不明显
private volatile Semaphore mPoolS
private static ImageLoade mI
* 队列的调度方式
* @author zhy
public enum Type {
FIFO, LIFO
* 单例获得该实例对象
public static ImageLoade getInstance() {
if (mInstance == null) {
synchronized (ImageLoade.class) {
if (mInstance == null) {
mInstance = new ImageLoade(1, Type.LIFO);
private ImageLoade(int threadCount, Type type) {
init(threadCount, type);
private void init(int threadCount, Type type) {
// loop thread
mPoolThread = new Thread() {
public void run() {
Looper.prepare();
mPoolThreadHander = new Handler() {
public void handleMessage(Message msg) {
mThreadPool.execute(getTask());
mPoolSemaphore.acquire();
} catch (InterruptedException e) {
// 释放一个信号量
mSemaphore.release();
Looper.loop();
mPoolThread.start();
// 获取应用程序最大可用内存
int maxMemory = (int) Runtime.getRuntime().maxMemory();
int cacheSize = maxMemory / 8;
mLruCache = new LruCache(cacheSize) {
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight();
mThreadPool = Executors.newFixedThreadPool(threadCount);
mPoolSemaphore = new Semaphore(threadCount);
mTasks = new LinkedList();
mType = type == null ? Type.LIFO :
* 加载图片
* @param path
* @param imageView
public void loadImage(final String path, final ImageView imageView) {
// set tag
imageView.setTag(path);
if (mHandler == null) {
mHandler = new Handler() {
public void handleMessage(Message msg) {
ImgBeanHolder holder = (ImgBeanHolder) msg.
ImageView imageView = holder.imageV
Bitmap bm = holder.
String path = holder.
if (imageView.getTag().toString().equals(path)) {
imageView.setImageBitmap(bm);
Bitmap bm = getBitmapFromLruCache(path);
if (bm != null) {
ImgBeanHolder holder = new ImgBeanHolder();
holder.bitmap =
holder.imageView = imageV
holder.path =
Message message = Message.obtain();
message.obj =
mHandler.sendMessage(message);
addTask(new Runnable() {
public void run() {
ImageSize imageSize = getImageViewWidth(imageView);
int reqWidth = imageSize.
int reqHeight = imageSize.
Bitmap bm = decodeSampledBitmapFromResource(path, reqWidth,
reqHeight);
addBitmapToLruCache(path, bm);
ImgBeanHolder holder = new ImgBeanHolder();
holder.bitmap = getBitmapFromLruCache(path);
holder.imageView = imageV
holder.path =
Message message = Message.obtain();
message.obj =
// Log.e("TAG", "mHandler.sendMessage(message);");
mHandler.sendMessage(message);
mPoolSemaphore.release();
* 添加一个任务
* @param runnable
private synchronized void addTask(Runnable runnable) {
// 请求信号量,防止mPoolThreadHander为null
if (mPoolThreadHander == null)
mSemaphore.acquire();
} catch (InterruptedException e) {
mTasks.add(runnable);
mPoolThreadHander.sendEmptyMessage(0x110);
* 取出一个任务
private synchronized Runnable getTask() {
if (mType == Type.FIFO) {
return mTasks.removeFirst();
} else if (mType == Type.LIFO) {
return mTasks.removeLast();
* 单例获得该实例对象
public static ImageLoade getInstance(int threadCount, Type type) {
if (mInstance == null) {
synchronized (ImageLoade.class) {
if (mInstance == null) {
mInstance = new ImageLoade(threadCount, type);
* 根据ImageView获得适当的压缩的宽和高
* @param imageView
private ImageSize getImageViewWidth(ImageView imageView) {
ImageSize imageSize = new ImageSize();
final DisplayMetrics displayMetrics = imageView.getContext()
.getResources().getDisplayMetrics();
final LayoutParams params = imageView.getLayoutParams();
int width = params.width == LayoutParams.WRAP_CONTENT ? 0 : imageView
.getWidth(); // Get actual image width
if (width &= 0)
width = params. // Get layout width parameter
if (width &= 0)
width = getImageViewFieldValue(imageView, "mMaxWidth"); // Check
// maxWidth
// parameter
if (width &= 0)
width = displayMetrics.widthP
int height = params.height == LayoutParams.WRAP_CONTENT ? 0 : imageView
.getHeight(); // Get actual image height
if (height &= 0)
height = params. // Get layout height parameter
if (height &= 0)
height = getImageViewFieldValue(imageView, "mMaxHeight"); // Check
// maxHeight
// parameter
if (height &= 0)
height = displayMetrics.heightP
imageSize.width =
imageSize.height =
return imageS
* 从LruCache中获取一张图片,如果不存在就返回null。
private Bitmap getBitmapFromLruCache(String key) {
return mLruCache.get(key);
* 往LruCache中添加一张图片
* @param key
* @param bitmap
private void addBitmapToLruCache(String key, Bitmap bitmap) {
if (getBitmapFromLruCache(key) == null) {
if (bitmap != null)
mLruCache.put(key, bitmap);
* 计算inSampleSize,用于压缩图片
* @param options
* @param reqWidth
* @param reqHeight
private int calculateInSampleSize(BitmapFactory.Options options,
int reqWidth, int reqHeight) {
// 源图片的宽度
int width = options.outW
int height = options.outH
int inSampleSize = 1;
if (width & reqWidth && height & reqHeight) {
// 计算出实际宽度和目标宽度的比率
int widthRatio = Math.round((float) width / (float) reqWidth);
int heightRatio = Math.round((float) width / (float) reqWidth);
inSampleSize = Math.max(widthRatio, heightRatio);
return inSampleS
* 根据计算的inSampleSize,得到压缩后图片
* @param pathName
* @param reqWidth
* @param reqHeight
private Bitmap decodeSampledBitmapFromResource(String pathName,
int reqWidth, int reqHeight) {
// 第一次解析将inJustDecodeBounds设置为true,来获取图片大小
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds =
BitmapFactory.decodeFile(pathName, options);
// 调用上面定义的方法计算inSampleSize值
options.inSampleSize = calculateInSampleSize(options, reqWidth,
reqHeight);
// 使用获取到的inSampleSize值再次解析图片
options.inJustDecodeBounds =
Bitmap bitmap = BitmapFactory.decodeFile(pathName, options);
private class ImgBeanHolder {
ImageView imageV
private class ImageSize {
* 反射获得ImageView设置的最大宽度和高度
* @param object
* @param fieldName
private static int getImageViewFieldValue(Object object, String fieldName) {
int value = 0;
Field field = ImageView.class.getDeclaredField(fieldName);
field.setAccessible(true);
int fieldValue = (Integer) field.get(object);
if (fieldValue & 0 && fieldValue & Integer.MAX_VALUE) {
value = fieldV
Log.e("TAG", value + "");
} catch (Exception e) {
ImageShowManager文件:图片的一些信息及其缓存情况的设置
package com.xiyouliwp.
* Created by lwp940118 on .
import java.io.F
import android.app.ActivityM
import android.app.A
import android.content.C
import android.graphics.B
import android.os.L
import android.support.v4.util.LruC
public class ImageShowManager {
private static ImageShowManager imageM
private static Application myA
private LruCache mMemoryC
private DiskLruCache mDiskC
// 硬盘缓存区域的大小,可以提升之前浏览过的图片的显示速度
private static final int DISK_CACHE_SIZE = 1024 * 1024 * 20;
// 硬盘缓存区域的文件名称
private static final String DISK_CACHE_SUBDIR = "thumbnails";
public static final int bitmap_width = 100;
public static final int bitmap_height = 100;
public static ImageShowManager from(Context context) {
// 如果不在ui线程中,则抛出异常
if (Looper.myLooper() != Looper.getMainLooper()) {
throw new RuntimeException("Cannot instantiate outside UI thread.");
if (myApp == null) {
myApp = (Application) context.getApplicationContext();
if (imageManager == null) {
imageManager = new ImageShowManager(myApp);
return imageM
* 私有的构造器为了保持单例模式
private ImageShowManager(Context context) {
/********** 初始化内存缓冲区 ******/
int memClass = ((ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
memClass = memClass & 32 ? 32 : memC
// 使用可用内存的1/8作为图片缓存
final int cacheSize = 1024 * 1024 * memClass / 8;
mMemoryCache = new LruCache(cacheSize) {
protected int sizeOf(String key, Bitmap bitmap) {
return bitmap.getRowBytes() * bitmap.getHeight();
/********* 初始化硬盘缓冲区 *********/
File cacheDir = DiskLruCache
.getDiskCacheDir(context, DISK_CACHE_SUBDIR);
mDiskCache = DiskLruCache.openCache(context, cacheDir, DISK_CACHE_SIZE);
* 将图片保存至本地缓存
* @param key
* @param value
public void putBitmapToDisk(String key,Bitmap value){
mDiskCache.put(key, value);
* 从硬盘缓存中读取图像
* @param url
public Bitmap getBitmapFormDisk(String url){
return mDiskCache.get(url);
* 从内存缓存区中获取bitmap,根据特定的url
* @param url
public Bitmap getBitmapFromMemory(String url){
return mMemoryCache.get(url);
* 将新的图片添加至内存缓存区
* @param key
* @param value
public void putBitmapToMemery(String key,Bitmap value){
mMemoryCache.put(key, value);
List_File_PopWind文件:弹出窗口的设置及其定义:
package com.xiyouliwp.
import java.util.L
import android.content.C
import android.graphics.drawable.BitmapD
import android.view.MotionE
import android.view.V
import android.view.View.OnTouchL
import android.widget.AdapterV
import android.widget.ListV
import android.widget.PopupW
* Created by lwp940118 on .
public class List_File_PopWind extends
BasePopupWindowForListView{
private ListView mListD
public List_File_PopWind(int width, int height,
List datas, View convertView) {
super(convertView, width, height, true, datas);
public void initViews() {
mListDir = (ListView) findViewById(R.id.listviwe_dir);
mListDir.setAdapter(new CommonAdapter(context, mDatas,
R.layout.list_dir_item) {
public void convert(ViewHolder helper, ImageFolder item) {
helper.setText(R.id.id_dir_item_name, item.getFolderName());
helper.setImageByUrl(R.id.id_dir_item_image,
item.getFirstImagePath());
helper.setText(R.id.id_dir_item_count, item.getImageCount() + "张");
public interface OnImageDirSelected {
void selected(ImageFolder floder);
private OnImageDirSelected mImageDirS
public void setOnImageDirSelected(OnImageDirSelected mImageDirSelected) {
this.mImageDirSelected = mImageDirS
public void initEvents() {
mListDir.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView parent, View view,
int position, long id) {
if (mImageDirSelected != null) {
mImageDirSelected.selected(mDatas.get(position));
public void init() {
protected void beforeInitWeNeedSomeParams(Object... params) {
abstract class BasePopupWindowForListView extends PopupWindow {
* 布局文件的最外层View
protected View mContentV
protected C
* ListView的数据集
protected List mD
public BasePopupWindowForListView(View contentView, int width, int height,
boolean focusable) {
this(contentView, width, height, focusable, null);
public BasePopupWindowForListView(View contentView, int width, int height,
boolean focusable, List mDatas) {
this(contentView, width, height, focusable, mDatas, new Object[0]);
public BasePopupWindowForListView(View contentView, int width, int height,
boolean focusable, List mDatas, Object... params) {
super(contentView, width, height, focusable);
this.mContentView = contentV
context = contentView.getContext();
if (mDatas != null)
this.mDatas = mD
if (params != null && params.length & 0) {
beforeInitWeNeedSomeParams(params);
setBackgroundDrawable(new BitmapDrawable());
setTouchable(true);
setOutsideTouchable(true);
setTouchInterceptor(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
dismiss();
initViews();
initEvents();
protected abstract void beforeInitWeNeedSomeParams(Object... params);
public abstract void initViews();
public abstract void initEvents();
public abstract void init();
public View findViewById(int id) {
return mContentView.findViewById(id);
protected static int dpToPx(Context context, int dp) {
return (int) (context.getResources().getDisplayMetrics().density * dp + 0.5f);
PopRecommend_ImageAdd_Adapter文件:返回时存放选择图片的gridview的适配器
package com.xiyouliwp.
import java.lang.ref.WeakR
import java.util.ArrayL
import android.app.A
import android.graphics.B
import android.graphics.C
import android.graphics.drawable.ColorD
import android.graphics.drawable.D
import android.os.AsyncT
import android.util.L
import android.view.LayoutI
import android.view.V
import android.view.ViewG
import android.widget.BaseA
import android.widget.ImageV
* Created by lwp940118 on .
public class PopRecommend_ImageAdd_Adapter extends BaseAdapter {
private Activity uiA
private ArrayList
private ImageShowManager imageM
private LayoutI
public PopRecommend_ImageAdd_Adapter(Activity a, ArrayList paths) {
this.uiActivity =
this.paths =
size = paths.size();
imageManager = ImageShowManager.from(uiActivity);
li = LayoutInflater.from(uiActivity);
public int getCount() {
// TODO Auto-generated method stub
public Object getItem(int position) {
// TODO Auto-generated method stub
public long getItemId(int position) {
// TODO Auto-generated method stub
public View getView(int position, View convertView, ViewGroup parent) {
SurfaceHolder surfaceHolder = new SurfaceHolder();
if (convertView != null) {
surfaceHolder = (SurfaceHolder) convertView.getTag();
convertView = li.inflate(R.layout.item_gridview_poprecommend, null);
surfaceHolder.iv = (ImageView) convertView
.findViewById(R.id.imageView1);
convertView.setTag(surfaceHolder);
String path = paths.get(position);
// 首先检测是否已经有线程在加载同样的资源(如果则取消较早的),避免出现重复加载
if (cancelPotentialLoad(path, surfaceHolder.iv)) {
AsyncLoadImageTask task = new AsyncLoadImageTask(surfaceHolder.iv);
surfaceHolder.iv.setImageDrawable(new LoadingDrawable(task));
task.execute(path);
return convertV
static class SurfaceHolder {
* 判断当前的imageview是否在加载相同的资源
* @param url
* @param imageview
private boolean cancelPotentialLoad(String url, ImageView imageview) {
AsyncLoadImageTask loadImageTask = getAsyncLoadImageTask(imageview);
if (loadImageTask != null) {
String bitmapUrl = loadImageTask.
if ((bitmapUrl == null) || (!bitmapUrl.equals(url))) {
loadImageTask.cancel(true);
// 相同的url已经在加载中.
* 负责加载图片的异步线程
* @author Administrator
class AsyncLoadImageTask extends AsyncTask {
private final WeakReference imageViewR
private String url =
public AsyncLoadImageTask(ImageView imageview) {
imageViewReference = new WeakReference(imageview);
protected Bitmap doInBackground(String... params) {
* 具体的获取bitmap的部分,流程: 从内存缓冲区获取,如果没有向硬盘缓冲区获取,如果没有从sd卡/网络获取
Bitmap bitmap =
this.url = params[0];
// 从内存缓存区域读取
bitmap = imageManager.getBitmapFromMemory(url);
if (bitmap != null) {
Log.d("dqq", "return by 内存");
// 从硬盘缓存区域中读取
bitmap = imageManager.getBitmapFormDisk(url);
if (bitmap != null) {
imageManager.putBitmapToMemery(url, bitmap);
Log.d("dqq", "return by 硬盘");
// 没有缓存则从原始位置读取
bitmap = BitmapUtilities.getBitmapThumbnail(url,
ImageShowManager.bitmap_width,
ImageShowManager.bitmap_height);
imageManager.putBitmapToMemery(url, bitmap);
imageManager.putBitmapToDisk(url, bitmap);
Log.d("dqq", "return by 原始读取");
protected void onPostExecute(Bitmap resultBitmap) {
if (isCancelled()) {
// 被取消了
resultBitmap =
if (imageViewReference != null) {
ImageView imageview = imageViewReference.get();
AsyncLoadImageTask loadImageTask = getAsyncLoadImageTask(imageview);
if (this == loadImageTask) {
imageview.setImageDrawable(null);
imageview.setImageBitmap(resultBitmap);
super.onPostExecute(resultBitmap);
* 根据imageview,获得正在为此imageview异步加载数据的函数
* @param imageview
private AsyncLoadImageTask getAsyncLoadImageTask(ImageView imageview) {
if (imageview != null) {
Drawable drawable = imageview.getDrawable();
if (drawable instanceof LoadingDrawable) {
LoadingDrawable loadedDrawable = (LoadingDrawable)
return loadedDrawable.getLoadImageTask();
* 记录imageview对应的加载任务,并且设置默认的drawable
* @author Administrator
public static class LoadingDrawable extends ColorDrawable {
// 引用与drawable相关联的的加载线程
private final WeakReference loadImageTaskR
public LoadingDrawable(AsyncLoadImageTask loadImageTask) {
super(Color.BLUE);
loadImageTaskReference = new WeakReference(
loadImageTask);
public AsyncLoadImageTask getLoadImageTask() {
return loadImageTaskReference.get();
ViewHolde文件:从sd卡中读取图片时gridview和listview的优化:
package com.xiyouliwp.
* Created by lwp940118 on .
import android.content.C
import android.graphics.B
import android.util.SparseA
import android.view.LayoutI
import android.view.V
import android.view.ViewG
import android.widget.ImageV
import android.widget.TextV
public class ViewHolder {
private final SparseArray mV
private int mP
private View mConvertV
private ViewHolder(Context context, ViewGroup parent, int layoutId,
int position) {
this.mPosition =
this.mViews = new SparseArray();
mConvertView = LayoutInflater.from(context).inflate(layoutId, parent,
mConvertView.setTag(this);
* 拿到一个ViewHolder对象
public static ViewHolder get(Context context, View convertView,
ViewGroup parent, int layoutId, int position) {
ViewHolder holder =
if (convertView == null) {
holder = new ViewHolder(context, parent, layoutId, position);
holder = (ViewHolder) convertView.getTag();
holder.mPosition =
public View getConvertView() {
return mConvertV
* 通过控件的Id获取对于的控件,如果没有则加入views
T getView(int viewId) {
View view = mViews.get(viewId);
if (view == null) {
view = mConvertView.findViewById(viewId);
mViews.put(viewId, view);
return (T)
* 为TextView设置字符串
public ViewHolder setText(int viewId, String text) {
TextView view = getView(viewId);
view.setText(text);
* 为ImageView设置图片
public ViewHolder setImageResource(int viewId, int drawableId) {
ImageView view = getView(viewId);
view.setImageResource(drawableId);
* 为ImageView设置图片
public ViewHolder setImageBitmap(int viewId, Bitmap bm) {
ImageView view = getView(viewId);
view.setImageBitmap(bm);
* 为ImageView设置图片
public ViewHolder setImageByUrl(int viewId, String url) {
ImageLoade.getInstance(3, ImageLoade.Type.LIFO).loadImage(url, (ImageView) getView(viewId));
public int getPosition() {
push_bottom_in.xml push_bottom_out.xml文件:定义弹出窗口的划入划出方式:
mybutton.xml按钮形状设置:
myedittext.xml 输入框的边框设置
下面给出demo中使用的布局文件
activity_image_add.xml
activity_main.xml
item_gridview_imageadd.xml
item_gridview_poprecommend.xml
list_dir_item.xml
list_dir.xml
最后别忘了给整个demo加入权限设置:

我要回帖

更多关于 2020年1月3日微博热搜 的文章

 

随机推荐