When I use cardUseCompatPadding to show shadow in my card view, top padding is bigger than left one. How to make both padding equal, because my ribbon looking not beautiful, it's bigger on top? Thanks.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Green triangles for badge -->
<FrameLayout
android:id="@+id/ribbon_parts"
android:layout_width="58dp"
android:layout_height="58dp"
android:background="@drawable/ic_ribbon_parts"
android:visibility="gone"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/item_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="@color/red"
android:clickable="true"
android:foreground="?attr/selectableItemBackground"
android:theme="@style/LightGrayHighlightTheme"
card_view:cardBackgroundColor="@color/white"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="2dp"
card_view:cardPreventCornerOverlap="true"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="130dp"
android:animateLayoutChanges="true"
android:orientation="horizontal"
android:background="@color/blue"
android:weightSum="3"> </LinearLayout>
</FrameLayout>
<!-- badge -->
<FrameLayout
android:id="@+id/ribbon_main"
android:layout_width="58dp"
android:layout_height="58dp"
android:background="@drawable/ic_ribbon_main"
android:visibility="gone"/>
Taken from the documentation:
Next, you can add the indentation you need by using the margin attribute
example.xml:
Now it looks great on different versions of the API.
API 19 example
API 26 example
comparison side by side
In your project, you can use these settings for both CardView and FrameLayout (ribbon) to achieve the desired result.
example_2.xml:
increased indentation
This is working for me, may be it would work for you too:
Thank You.
You can't fix this. When
cardUseCompatPadding
flag is set, these methods are used to calculate padding on all API levels:addPaddingForCorners
is true when you usecard_view:cardPreventCornerOverlap="true"
.Perhaps setting some
layout_marginTop
onribbon_main
andribbon_parts
will give you the desired effect?