CardView中的ImageView在Android 4.3上不显示半径 [英] ImageView in CardView not show radius on Android 4.3
问题描述
这是我的布局xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/catalog_item_card_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
card_view:cardCornerRadius="5dp"
card_view:cardUseCompatPadding="true">
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/imageViewPhoto"
android:layout_width="wrap_content"
android:layout_height="160dp"
android:src="@drawable/test_merchant_preview"
card_view:layout_constraintLeft_toLeftOf="parent"
card_view:layout_constraintRight_toRightOf="parent"
card_view:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
这是Andrdoid 5.0+上的结果
Here result on Andrdoid 5.0+
如您所见,ImageView成功显示为半径.好吧.
As you can see the ImageView success show with radius. OK.
现在,我在Android 4.3上运行应用程序.
Now I run app on Android 4.3.
结果如下:
如您所见,ImageView显示为无半径. 为什么?
As you can see the ImageView show without radius. Why?
推荐答案
CardView中的ImageView在Android 4.3上不显示半径
ImageView in CardView not show radius on Android 4.3
CardView
高度仅适用于android 5.0及更高版本
CardView
elevation only work on android 5.0 and above
CardView
使用Lollipop上的height属性来生成阴影,并回退到旧平台上的自定义仿真阴影实现.
CardView
uses elevation property on Lollipop for shadows and falls back to a custom emulated shadow implementation on older platforms.
由于圆角裁剪的昂贵特性,在Lollipop之前的平台上,CardView
不会裁剪与圆角相交的子级.相反,它添加了填充来避免这种交集
Due to expensive nature of rounded corner clipping, on platforms before Lollipop, CardView
does not clip its children that intersect with rounded corners. Instead, it adds padding to avoid such intersection
更多信息在此处阅读
这篇关于CardView中的ImageView在Android 4.3上不显示半径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!