13

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.

Community
  • 1
  • 1
Want
  • 820
  • 2
  • 9
  • 20
  • Please consider starring this feature request: https://issuetracker.google.com/issues/37076423 – Mark May 20 '17 at 13:29

2 Answers2

16

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.

Bartek Lipinski
  • 30,698
  • 10
  • 94
  • 132
  • Thank you for the answer! Could you please tell me how could I modify the implementation to support swiping multiple cards (not just one) with one 'strong' swipe? – Want Feb 03 '15 at 21:34
  • Cant really think of any "quick-and-easy" solutions... I think you would have to implement something similiar to this: http://stackoverflow.com/a/14969879/1993204 , but supporting `VerticalViewPager` instead of the horizontal one. BTW feel free to accept the answer if it helped you. – Bartek Lipinski Feb 03 '15 at 22:22
  • @blipinsk can I customise your lib where I can swipe views to left and right to discard? I want to give effect to stack view as Tinder like swipe functionality. – Bharat Dodeja Aug 12 '15 at 13:58
  • Hello @BartoszLipinski Thanks for the awesome library . One question is there any way to have vertical and horizontal flip with init Thanks. – Rajnish Mishra Dec 09 '15 at 10:18
  • @Bartosz Lipinski Thanks for library, it looks great! Is there a way to implement my own adapter so that every fragment will include different data, for example Editexts with different names? – MorZa Jan 24 '16 at 12:29
  • 1
    @Mor sure thing... it just works with a regular `PagerAdapter`. You can use e.g. `FragmentStatePagerAdapter` and overide `getItem` to return a different `Fragment` for a particular position inside `ViewPager` – Bartek Lipinski Jan 24 '16 at 13:38
  • Hi, any ideas on how to change the item display at front programatically? I would like to display the StackView but move it using two buttons. Thanks! – Roberto May 27 '16 at 12:23
  • @Lancelot I answered you in the issue you've created over at github. – Bartek Lipinski May 27 '16 at 12:24
  • @BartekLipinski Thank you!!!! Just saw it. I'm testing it now, in case anyone else is looking at this, as a normal ViewPager it has the method setCurrentItem available. – Roberto May 27 '16 at 13:51
8

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.

Simas
  • 43,548
  • 10
  • 88
  • 116