Android ScrollView剪辑子高程阴影[重复]

问题描述 投票:13回答:3

这个问题在这里已有答案:

正如标题所述,我正在尝试将一个CardView放在ScrollView中,但是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添加填充或向子CardView添加边距...

有没有选项可以防止这种情况发生而不使用填充/边距?

谢谢。

编辑:

这是布局看起来没有在父滚动视图上设置填充的方式,因为可以看到,左右阴影被切断:Child's side shadow being cut off by parent scroll view

现在,如果将填充添加到父滚动视图侧,则可以正确绘制阴影,如下所示:Child's side shadow now shown correctly after adding padding to right and left side of scrollview

所以,我的主要问题是这是实现这一目标的唯一方法吗?或者父视图上有一个标记或配置,可以正确绘制它的子视图?

android android-scrollview android-elevation
3个回答
38
投票

这对我来说也是一个类似的问题:

获取子视图以显示阴影的正确方法是在父级上设置填充并在该父级上设置android:clipToPadding =“false”。

在这里找到:Android "elevation" not showing a shadow


17
投票

我遇到了同样的问题,我通过将cardUseCompatPadding属性添加到卡片视图来解决它:

app:cardUseCompatPadding="true"

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


-2
投票

这项工作为我添加cardUseCompatPadding属性到卡视图:

在该父级上设置android:clipToPadding =“false”。

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