问题
I have searched the internet but I couldn't find some good explanation or advice. Basically, I want to implement this functionality.
on slide downI used the StackView class and all I get is this "diagonal" stack
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.
回答1:
Feel free to use my library available 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.
回答2:
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.
来源:https://stackoverflow.com/questions/28098168/how-to-implement-customized-stack-view-in-android