What is the proper way to expand a CardView?
CardView is a new widget in Android that can be used to display any sort of data by providing a rounded corner layout along with a specific elevation. CardView is the view that can display views on top of each other. The main usage of CardView is that it helps to give a rich feel and look to the UI design.
CardView uses elevation property on Lollipop for shadows and falls back to a custom emulated shadow implementation on older platforms. Due to expensive nature of rounded corner clipping, on platforms before Lollipop, CardView does not clip its children that intersect with rounded corners.
Put an id to the TextView you want to change during card view click event. Then setOnclickListener to the CardView, on the callback of clicklistener get the reference of the TextView if it exists set a new text to it.
Use an expandable list view with cardview
or even
You can use wrap content as height of cardview and use textview inside it below title, so on click make the textview visible and vice-versa.
but isn't it bad design ?
nope it isn't if you give some transition or animation when it's expanded or collapsed
If you want to see some default transition then just write android:animateLayoutChanges="true" in parent layout.
If you are using CardViews inside a ListView or RecyclerView see my answer for recommended way of doing it: RecyclerView expand/collapse items
If you are just using CardView the do this in your on onClickListener of cardview:
TransitionManager.beginDelayedTransition(cardview); detailsView.setVisibility(View.VISIBLE);
By default keep the visibility of your detailsView to be GONE in your xml.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With