如何按日期制作排序图库缩略图 [英] How to make sort gallery thumbnails image by date
本文介绍了如何按日期制作排序图库缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个Android应用程序。此应用程序从库中获取所有缩略图图像。我想按日期排序这些缩略图,但我不能这样做。
I am developing an android applicaiton. This application get all thumbnail images from gallery. I want to sort these thumbnails by date, but I can't do it.
请帮帮我。
获取所有图片
// Set up an array of the Thumbnail Image ID column we want
String[] columns = {MediaStore.Images.Media._ID};
String orderBy = MediaStore.Images.Thumbnails._ID + " DESC LIMIT 10";
// Create the cursor pointing to the SDCard
cursor = getActivity().managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
columns, // Which columns to return
null, // Return all rows
null,
orderBy);
// Get the column index of the Thumbnails Image ID
columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
myGalleryImages = (GridView) view.findViewById(R.id.my_gallery);
myGalleryImages.setAdapter(new ImageAdapter(getActivity()));
设置图片
// Move cursor to current position
cursor.moveToPosition(position);
// Get the current value for the requested column
int imageID = cursor.getInt(columnIndex);
// Set the content of the image based on the provided URI
holder.image.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, "" + imageID));
推荐答案
更新列
和 orderBy
像这样:
String[] columns = {MediaStore.Images.Media._ID, MediaStore.Images.ImageColumns.DATE_TAKEN};
String orderBy = MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC";
并查看是否有帮助。
您还可以获取真实图像而不是缩略图,并使用图像加载库来处理正确的重新调整大小。在这种情况下,将缩略图
引用替换为 ImageColumns
You could also fetch real images instead of thumbnails and use image loading library that will take care of proper re-sizing. In this case replace your Thumbnails
references with ImageColumns
这篇关于如何按日期制作排序图库缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文