CardView cardUseCompatPadding

I am developing an Android application for both Lollipop and previous versions.

I use CardView (this CardView does not have a child, it is just placed behind my View) to create a shadow.

But the problem arises when it works on pre Lollipop devices.

so I set cardUseCompatPadding to true. I am wondering if I can get the value of this add-on?

Where can I find a link to a value?

+4
source share
2 answers

, CardView, , . RoundRectDrawableWithShadow .

, - :

    float elevation = cardView.getMaxCardElevation();
    float radius = cardView.getRadius();
    double cos45 = Math.cos(Math.toRadians(45));

    int horizontalPadding = (int) (elevation + (1 - cos45) * radius);
    int verticalPadding = (int) (elevation * 1.5 + (1 - cos45) * radius);
+3

CardView.

, - Lollipop newer getUseCompatPadding() - false.

android:elevation="3dp" app:elevation="3dp"

CardView Lollipop .

- Lollipop CardView , . , (. setPreventCornerOverlap (boolean), ).

Lollipop CardView . maxCardElevation + (1 - cos45) * cornerRadius maxCardElevation * 1.5 + (1 - cos45) * cornerRadius .

padding , CardView. XML setContentPadding (int, int, int, int) CardView CardView.

, CardView, , Lollipop Lollipop. api , . , , CardView Lollipop as , setUseCompatPadding (boolean) true.

CardView , setCardElevation ( ). CardView API Lollipop Lollipop . , getMaxCardElevation(). , setMaxCardElevation (float), CardView .

-1

Source: https://habr.com/ru/post/1623272/


All Articles