Android ScrollView剪裁子高程阴影

Android ScrollView剪裁子高程阴影,android,android-scrollview,android-elevation,Android,Android Scrollview,Android Elevation,正如标题所述,我正试图将CardView放在ScrollView中,但是CardView的父视图关闭了CardView的立面阴影 这是布局XML: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.c

正如标题所述,我正试图将CardView放在ScrollView中,但是CardView的父视图关闭了CardView的立面阴影

这是布局XML:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".TestScrollViewActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="128dp"
        android:background="?colorPrimary"
        android:gravity="bottom"
        android:minHeight="?actionBarSize"/>

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal"
        android:clipToPadding="false"
        android:paddingBottom="40dp"
        android:paddingTop="60dp">

        <android.support.v7.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:elevation="4dp"
            app:cardBackgroundColor="@android:color/white"
            app:cardCornerRadius="0dp">

            <LinearLayout
                android:layout_width="400dp"
                android:layout_height="600dp"
                android:orientation="vertical">

            </LinearLayout>

        </android.support.v7.widget.CardView>

    </ScrollView>

</FrameLayout>

现在,如果将填充添加到父scrollview侧,阴影将正确绘制,如图所示:


因此,我这里的主要问题是,这是实现这一点的唯一方法?或者父视图上有一个标记或配置,允许正确绘制其子视图?

这对我来说在一个类似的问题中起到了作用:

让子视图显示阴影的正确方法是在父视图上设置填充,并在父视图上设置android:clipToPadding=“false”


如图所示:

我也遇到了同样的问题,我通过在卡片视图中添加cardUseCompatPadding属性解决了这个问题:

app:cardUseCompatPadding="true"

使用此解决方案后,阴影将不会被剪切或裁剪。

将cardUseCompatPadding属性添加到卡视图中对我有用:


在那个家长身上设置android:clipToPadding=“false”

请分享布局的屏幕截图,看看它是什么样子以及你希望它是什么样子。是的,恐怕这是目前唯一的方法。太好了!这将扩展列表阴影,并且不考虑填充,正如所需。回答得很好。谢谢。在2020年中期仍然相关。谢谢你,这对我有用。但是我在写这行的时候,有一个关于空间的问题。知道为什么空间会增加吗