Open ShawnTheBeachy opened 6 years ago
The card disappears because the card height is 0. When the card expands, in expand() method, the line: final int initialHeight = card.getHeight(); gives the card height as 0. When the card collapses, since it's initial height is 0, it does not shows.
To fix this, you can give some delay(10 milli sec) and then expand the card.
@shubham171294 can you explain how that delay works, please?
new Handler().postDelayed(new Runnable() { @Override public void run() { card.setExpanded(true); } }, 10);
The delay works because when the system is inflating the layout, the card is not yet expanded. So we give some delay so that the layout is inflated first and then the card is expanded. If we don't give the delay, at layout calculation time the height comes out to be 0.
new Handler().postDelayed(new Runnable() { @Override public void run() { card.setExpanded(true); } }, 10);
The delay works because when the system is inflating the layout, the card is not yet expanded. So we give some delay so that the layout is inflated first and then the card is expanded. If we don't give the delay, at layout calculation time the height comes out to be 0.
Doesn't work
If
startExpanded
is set totrue
the CardView starts expanded, but when tapped it disappears completely.