开发者

How to program an image chooser in Android? [duplicate]

开发者 https://www.devze.com 2023-01-04 16:30 出处:网络
This question already has answers here: Access pictures from Pictures app in my android app 开发者_如何学运维
This question already has answers here: Access pictures from Pictures app in my android app 开发者_如何学运维 (3 answers) Closed 9 years ago.

I would like to program a image picker which should choose an image from the library. Is it possible to do this in a smooth way with the Android sdk? I'm pretty new to Android programming.


You should check Image-Gallery.


There are a few options: The simplest: If you want to have a strip of images, just add them all to a linear layout with horizontal orientation, and add the linear layout to HorizontalScrollView. Cons: It would not let you stop on an image.

My favourite, the more advanced one: As suggested above: Gallery. The gallery requires an adapter to fetch view at position n. It goes like this: You create an object that extends BaseAdapter and it creates views from images

myView = new ImageView();
myView.setImageDrawable( new BitmapDrawable.createFromPath("<path>") )

Another, more advanced way: There is that ImageSwitcher. It displays a gallery plus an image. See This page I have found when I encountered the same problem

Two important tips:

  1. Don't try to hack widgets implementing them manually. The performance might be bad.
  2. It's very recommended reading carefully about interfaces like Gallery. They offer lots of goodies and even more than that if you extend them.

Thanks

M.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号