AleSpero / ExpandableCardView

Simple expandable CardView for Android.
Apache License 2.0
689 stars 88 forks source link

StartExpanded doesn't work #25

Open ShawnTheBeachy opened 6 years ago

ShawnTheBeachy commented 6 years ago

If startExpanded is set to true the CardView starts expanded, but when tapped it disappears completely.

shubham08gupta commented 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.

joseRelvasF3m commented 5 years ago

@shubham171294 can you explain how that delay works, please?

shubham08gupta commented 5 years ago

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.

shahzad1 commented 3 years ago

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