Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement customized stack view in android?

I have searched the internet but I couldn't find some good explanation or advice. Basically, I want to implement this functionality.

enter image description here on slide down

enter image description here

enter image description here

I used the StackView class and all I get is this "diagonal" stack

enter image description here

I want views to be one behind another, as in the pictures above.

Similar question is asked here -> Android customize stackview, but I couldn't find any satisfying answers.

I have read the code for StackView as suggested, but honestly, I don't know how would I customize it to get what I want. When I change the value of PERSPECTIVE_SHIFT_FACTOR_X or PERSPECTIVE_SHIFT_FACTOR_Y nothing changes and I get the same "diagonal view". Am I missing something?

Thanks in advance for the answers.

like image 261
Want Avatar asked Jan 22 '15 20:01

Want


2 Answers

Feel free to use my library available here.

enter image description here

It does exactly what you want and is based on the ViewPager so you can use it with just a typical PagerAdapter of your choice.

like image 153
Bartek Lipinski Avatar answered Nov 17 '22 07:11

Bartek Lipinski


You can't change the original PERSPECTIVE_SHIFT_FACTOR_X because it's a private field.

StackView uses many classes which have package visibility and are only usable in package android.widget.

Furthermore some of those classes are pre-compiled and the source is nowhere to be found, so you can't just copy-paste them and create your own custom StackView from zero.

You can make the views appear in a column by overriding onLayout, but once you animate them, their positions are changed back to the default. Sadly the view animations are done in private methods of StackView so nothing you can do about that either.

You're better of creating your own class that does this, and you can reference the code used in the StackView source. Creating such a class could be a lot of work and it's definitely not in the scope of a single question.

like image 8
Simas Avatar answered Nov 17 '22 07:11

Simas