[英]Cardview shadow looks different when inside a ScrollView
I stumbled upon something weird. 我偶然发现了一些奇怪的东西。 I am using the same
CardView
component in more than one place in my app, all with the same elevation (3dp), and they all looks the same. 我在应用程序的多个位置中使用了相同的
CardView
组件,它们的仰角(3dp)都相同,而且它们看起来都一样。 However, for one scenario I need to embed the CardView
inside a ScrollView
. 但是,对于一种情况,我需要将
CardView
嵌入ScrollView
。 I didn't change anything in the CardView
configuration, but the shadow now looks different. 我没有更改
CardView
配置中的任何内容,但是阴影现在看起来有所不同。
This is my layout: 这是我的布局:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:padding="16dp"
android:scrollbars="none">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
app:cardCornerRadius="8dp"
app:cardElevation="3dp"
app:cardUseCompatPadding="true">
<!-- some other views-->
</androidx.cardview.widget.CardView>
</ScrollView>
In the picture below you can see on the right the CardView
and on the left the two shadows: on the top the shadow generated by the CardView
alone, on the bottom the one generated when the CardView
is inside a ScrollView
. 在下面的图片中,您可以在右侧看到
CardView
,在左侧看到两个阴影:顶部是单独由CardView
生成的阴影,底部是当CardView
在ScrollView
内时生成的CardView
。 As you can see the second one appears darker and thicker. 如您所见,第二个看起来更暗更浓。
NOTE: The background color (#FAFAFA) is the same in both scenario. 注意:在两种情况下,背景颜色(#FAFAFA)相同。
For both cases, I would check the following properties as it could contribute to the difference you're seeing: 对于这两种情况,我都会检查以下属性,因为这可能会导致您所看到的差异:
getTranslationZ()
getElevation()
getOutlineAmbientShadowColor()
(this is only valid in API 28+) getOutlineAmbientShadowColor()
(仅在API 28+中有效) getOutlineSpotShadowColor()
(this is only valid in API 28+) getOutlineSpotShadowColor()
(仅在API 28+中有效) Plus, checking Layout inspector to see if there's any view that could affect to the rendering. 另外,检查布局检查器以查看是否有任何可能影响渲染的视图。
Also, this article from Sebastiano Poggi could be of help. 另外,塞巴斯蒂亚诺·波吉(Sebastiano Poggi)的这篇文章可能会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.