The CardView widget has a setElevation(4f) parameter that runs on the API >= 21 . For API < 21 there is a cardView.setCardElevation(4f) , but it does not work.

 CardView cardView = new CardView(getActivity()); if (Build.VERSION.SDK_INT >= 21) { cardView.setElevation(4f); } else { cardView.setCardElevation(40f); } 

I don’t call or still need to create a new View with my hands, paint it in a gradient, and then cardView.addView(myGradienShadow); like a shadow?

  • Maybe it’s easy to create a view with a cardview on board, assign an id to it, and then find a shadow in the code to find it?: D - DenShDen
  • @DenShDen, the thing is, I create a cardView in a loop and fill it there. In the markup only LinearLayout , in which everything is then added via addView . I did it earlier through LinearLayout, to which I added a View with a gradient of the fill color LinearLayout. But the shadow was not very likely and plausible. I decided to cardView into the cardView theme, and here is the problem with elevation. - web_alex
  • Essentially set in the code? you can in xml set the attribute card_view: cardElevation = "". But only the component taken from the library of support, as "android.support.v7.widget.CardView" - Werder
  • @Werder, yes. The cycle constantly creates a different number of these cards. - web_alex
  • @web_alex for 17 and up works? - anber

0