如何为android实现自定义设备照片库? [英] How to implement custom device photos gallery for android?

查看:23
本文介绍了如何为android实现自定义设备照片库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发包含基本图片库功能的 Android 应用程序.我设法构建了从我的应用程序后端 API 获取照片列表的活动,并在活动布局内的 android gridview 中呈现它们.

这是目前的样子:

但是,我很难为由相机拍摄并存储在设备上的用户设备照片构建相同的图库体验.我考虑过的两种解决方案是:

  1. 建立自己的图片库.
  2. 使用 Intent 启动默认的 android 图片库.

解决方案 1:我相信第一个解决方案会花费我太多时间来开发.我从本教程开始,但是一旦我实施了它,我发现它运行得太慢了.然后我看看android相机source代码来寻找解决方案,但我再次发现检查代码并从头开始构建我自己的图库需要花费太多时间.我还认为,重写已经存在的功能并不符合 Android 操作系统的理念,而是使用 Intent 来启动可以处理您需要的操作的活动.这让我想到了第二种解决方案.

解决方案 2: 我尝试使用 Intent 调用默认的 android 库,以便在我很快再次被卡住之前浏览用户的设备照片.这次的问题是,一旦用户点击照片,图库就会退出并返回到最初启动它的活动,我希望(并且我希望)改为开始大图像预览.我看到其他人也有这个问题如何通过意图打开画廊而没有结果.因为我没有找到解决这个问题的方法,所以我决定退出.

我的问题是如何克服这些问题并构建与我已有的用于网络照片的图库类似的图库.如果有人能给我参考,我将不胜感激.

解决方案

这个问题已经很老了,但是因为它有很多观点和很多赞成票,所以最好给出一个答案.

所以,首先教程有所改进,您可以为您的#1选项找到一些很酷的东西:

  • 这个是我喜欢的
  • 这个 使用了不推荐使用的 UI 元素,但也很酷
  • 使用适配器对我来说,这是最好的方式.

对于您的 #2 选项,我不认为有任何不返回原始活动的想法,因为您仍然无法控制通过系统发送的意图的结果.

但是还有另一个您没有提到的解决方案:有一些非常酷的库,您可以对其进行自定义以获得您想要的内容:

  • 这个有点花哨
  • 这个似乎也很酷,但您可能会遇到导入问题因为它不是 gradle 项目
  • 这个是我肯定会使用的.

I'm working on android application that will have basic image gallery functionality included. I've managed to build activity that fetches list of photos from my application backend API and render them in android gridview within activity layout.

This is how it looks like at the moment:

However I'm having difficulties to build same gallery experience for user's device photos that were taken by camera and stored on device. Two solutions I considered were:

  1. Building my own image gallery.
  2. Starting default android image gallery using intent.

Solution 1: I belive that first solution will take me too much time to developed. I started with this tutorial but as soon I implemented it I found out that it is running too slow. Then I take a look at android camera source code to find solution but again I found that it will take me too much time to review the code and to build my own gallery from scratch. I also believe that it is not in Android OS philosophy to rewrite functionalities that already exists but to use Intents to start activities that can handle actions you need. This lead me to second solution.

Solution 2: I tried calling default android gallery using intent in order to browse user's device photos by soon I was stuck again. Problem this time was that as soon as user tap on photo, gallery exits and returns to activity that originaly started it, and I expected (and I want) to start large image preview instead. I saw that others had this problem too how to open gallery via intent without result. Because I didn't find the fix for this I decided to quit.

My question is how can I overcome these problems and build gallery that is similar to one I already have for web photos. If anyone could give me reference I would be most thankful.

解决方案

this question is pretty old but, as it has a lot of views and quite a lot of upvotes, it could be good to bring an answer to it.

So, first the tutorials evolved a bit and you can find some cool stuff for your #1 option:

  • This is the one I prefer
  • This one uses a deprecated UI element but is also cool
  • This uses an Adapter which is, to me, the best way to proceed.

For your #2 option, I do not see any idea to not to return to the original activity because you still do not have control over the result of the intent you send through the system.

But there are another solution that you didn't mention: there are librairies which are very cool and that you could customise to get exactly what you want:

  • This one is a bit fancy
  • This one seems also to be pretty cool but you could have problems importing it because it's not a gradle project
  • This is the one I would definitely use.

这篇关于如何为android实现自定义设备照片库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆