Android ScrollView 裁剪子高程阴影

标签 android android-scrollview android-elevation

<分区>

如标题所述,我正在尝试将 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 添加边距...

是否有任何选项可以在不使用填充/边距的情况下防止这种情况发生?

谢谢。

编辑:

这是在父 ScrollView 上没有设置填充的情况下布局的样子,可以看到,左右阴影被切断了: Child's side shadow being cut off by parent scroll view

现在,如果将填充添加到父 ScrollView 的边,阴影将被正确绘制,如下所示: Child's side shadow now shown correctly after adding padding to right and left side of scrollview

所以,我的主要问题是这是实现该目标的唯一方法?还是父 View 上有标签或配置允许正确绘制其 subview ?

最佳答案

这只是在类似的问题上对我有用:

the right way to get a child view to show shadow is to set padding on the parent and set android:clipToPadding="false" on that parent.

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

关于Android ScrollView 裁剪子高程阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33834402/

相关文章:

android - 检查文件是图像还是视频

android - android棉花糖中的存储权限

java - 当相对布局包含自定义 View 时滚动它

android - 从下到上滚动 ListView

shadow - ConstraintLayout 中带有标高和阴影的 View

android - 从android中的firebase数据库向多个号码发送消息

Android - 按钮按下事件上的图像 - 将图像叠加应用于所有

android - 如何检测ScrollView是否正在滚动

android - 我如何才能提升 ListView 项目?

android - Material TabLayout 标高不起作用