在ScrollView中,Cardview阴影看起来不同

问题描述 投票:1回答:1

我偶然发现了一些奇怪的事情。我在我的应用程序中的多个位置使用相同的CardView组件,所有组件都具有相同的高度(3dp),并且它们看起来都相同。但是,对于一种情况,我需要将CardView嵌入到ScrollView中。我没有更改CardView配置中的任何内容,但阴影现在看起来不同了。

这是我的布局:

<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>

在下面的图片中,您可以看到右侧的CardView,左侧是两个阴影:顶部是单独的CardView生成的阴影,底部是CardView位于ScrollView内部时产生的阴影。如你所见,第二个看起来更暗更厚。

注意:两种方案中的背景颜色(#FAFAFA)都相同。

enter image description here

android android-cardview android-scrollview android-elevation
1个回答
0
投票

对于这两种情况,我会检查以下属性,因为它可能会导致您看到的差异:

  • getTranslationZ()
  • getElevation()
  • getOutlineAmbientShadowColor()(仅在API 28+中有效)
  • getOutlineSpotShadowColor()(仅在API 28+中有效)

另外,检查布局检查器以查看是否存在可能影响渲染的任何视图。

此外,Sebastiano Poggi的this article可能会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.