Alternative views instead of Stackviews for android versions lower to android 3.0

I am trying to implement StackView behaviour in my application but I believe this widget is only available from android 3.0 onwards. I am an intermediate developer for android OS and hence have limited knowledge on customized views.

Could some one please provide some pointers as to how i can achieve Stackview in android 2.2/2.3?

Upvotes: 4

Views: 1693

Answers (1)

Joseph Earl
Joseph Earl

Reputation: 23432

There is no component in the SDK with this exact functionality prior to API Level 11 (3.0), so you will need to create your own custom View to get the desired effect.

The easiest/quickest way would be to create a custom view that extends FrameLayout since children of a FrameLayout automatically stack on top of each other and your custom view will inherit this behaviour. You'll also want to override the way children are laid out so that you adjust the x and y position of the children depending on where they are in the stack.

You will have to make your own methods to go to the next/previous view - you'd have to do this by re-ordering the the child views (remove them all, then add them back in the new order).

The solution I've described doesn't include the view recycling you get with AdapterViews, so wouldn't be suitable for a large number of stacked items.

Alternatively, find the StackView source code and copy it into your project, though this will probably also involve copying a large amount of other Android classes into your project, since StackView will undoubtedly access private members of super-classes that are only accessible from the widgets package (without Reflection).

Upvotes: 7

Related Questions