0

I am beginner in android animations and therefore, am wondering exactly how can I implement something like expand a cardView to show hidden options or elements.

For example: a post in social networking, we have a cardView holding the post info. it also has likes and comments buttons/options. When user taps on comments button the view should expand a little say certain height and show the comments and shrink back when the same button is tapped again.

I am listing my posts using RecyclerView in a Fragment using a CardView. I am looking for a soft animation along with expanding and shrinking back to original place or size.

Below is a screenshot that might help you understand what exactly I want:

enter image description here

How to do this? Will you please provide me a small snippet of code?

James Z
  • 12,209
  • 10
  • 24
  • 44
Kaushal
  • 217
  • 1
  • 4
  • 12
  • try `ExpandableLayout` to achieve this. Check https://github.com/cachapa/ExpandableLayout. – Ajay Mehta May 03 '19 at 09:28
  • You can try foldable cardview https://github.com/Ramotion/folding-cell-android – Santanu Sur May 03 '19 at 09:29
  • What if you simply set CardView's height to wrap_content, and set android:animateLayoutChanges=true, and then just show/hide part of layout inside? – RadekJ May 03 '19 at 09:54

1 Answers1

0

use wrap content as height of cardview and use textview inside it below title, so on click make the textview visible and invisible.

And use android:animateLayoutChanges="true" in parent layout.

Sajith
  • 713
  • 6
  • 21