首页 > 解决方案 > 圆形背景 android 的阴影

问题描述

我有一个背景可绘制对象,它只有两个带有半径的角。

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:topLeftRadius="6dp" android:bottomLeftRadius="6dp"></corners>
</shape>

我将它应用于文本视图。我还为它附加了一个大纲提供程序。

 <android.support.v7.widget.AppCompatTextView
        android:id="@+id/textView71"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="64dp"
        android:background="@drawable/left_rounded_border_6dp"
        android:backgroundTint="@color/colorAccent"
        android:padding="@dimen/unit_medium"
        android:elevation="10dp"
        android:outlineProvider="bounds"
        android:text="Challenge"
        android:textAppearance="@style/TextAppearance.Heading5"
        android:textColor="@color/colorTextWhite"
        app:layout_constraintBottom_toTopOf="@+id/company_logo_iv"
        app:layout_constraintEnd_toStartOf="@+id/textView73"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

这是我看到的影子。

在此处输入图像描述 仔细观察,您会发现阴影并未完全应用在曲线上。相反,它应用于矩形区域。

我不知道为什么会这样。

标签: android

解决方案


高程根据视图的轮廓提供程序创建阴影。这默认为背景可绘制的边界 - 这是完美的矩形。

您可以创建和设置自己的圆角轮廓提供程序 - 请参阅https://developer.android.com/training/material/shadows-clipping#Shadows


推荐阅读