Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: a vertical gallery?

I'm looking for a widget that behaves similar to the gallery widget but scrolls vertically instead of horizontally. I googled all around and apparently the answer is no such pre-made widget exists.

So I said myself, oh well, I'll look at the gallery class in the android source and modify that to scroll vertically instead. Not so easy. The android SDK hides a lots away (understandably for framework maintenance), but it also makes it very hard to extend the widgets. The gallery class, for example, use a lots of member variable from its parent, AbsSpinner (mSelectedPosition, etc.etc.), and its parent's parent, etc... which are not at all accessible from the app-developer's standpoint. Without access to those member variable, I cannot use similar code from gallery class for my own use.

Short of moving up the inheritance chain and put the source code of those parent classes all in my project, or writing the widget all from scratch without using the existing framework widgets that already solved the problem, I can't find a way to get a vertical scrolling gallery.

Is there a better way around? Why does the android framework make extending widget so difficult?

like image 669
polyglot Avatar asked Feb 20 '10 16:02

polyglot


People also ask

How do I change the layout of my photos on Android?

Change the layout of your photo: Tap the photo. You can also drag within the photo to position it. Reorder and delete pages. Touch and hold a page to select it, then drag it to reorder.

Can you layer photos on Android?

Photo Layers is the android editing app with simple features. You can easily cut, crop and blend different pictures into one with the convenient user interface. Either I can say you can play with its tools to get a pitch-perfect picture.

Which gallery app is best without ads?

Simple Gallery - Photo and Video Manager & Editor The app is ad-free, and the pro version gives you access to more perks, such as protecting access to the app with a PIN or fingerprint, as well as the option to create secret folders.


1 Answers

Is there a better way around?

Since we don't know what you are building, that's impossible to say. I agree with Yoni Samlan's comment that a ListView may be sufficient for your needs.

Why does the android framework make extending widget so difficult?

While it is conceivable that a reimplemented Gallery might make it simpler for you to make it orient differently, the core Android team has to weigh such reimplementation against other development priorities.

One of those priorities is SDK fidelity. They want to make sure that, to the greatest extent possible, code written for Android 1.5 can run on Android 2.1 without modification. This limits them in two ways. First, they cannot just change the existing Gallery, for example, to accommodate your desires, if doing so causes them to break their existing API. Second, the core Android team will not expose new methods or classes, even if those might be beneficial to third-party developers, unless and until the team is ready to support those methods or classes for the long haul.

Android was initially written before an SDK existed. That's the reason given for why most of the built-in applications (e.g., calculator) cannot be built with the SDK alone, but needs to be built as part of a firmware image. Similarly, the core Android team had to make a decision, as part of creating the initial SDK, of how best to take the existing code and create public stuff we can work with and protected/private stuff we cannot, with SDK fidelity in mind. As you may have noticed, Android is vast, and so creating the SDK must have taken a correspondingly vast amount of staff time. Rewriting lots of it to increase the odds that somebody could, say, create a vertical Gallery wasn't probably high on their list.

In an ideal world, yes, we would be able to more readily extend built-in widgets and significantly modify their behavior. Similarly, in an ideal world, I would have hair... :-)

like image 56
CommonsWare Avatar answered Sep 19 '22 07:09

CommonsWare