具有不同角半径的可绘制形状背景的布局上的高程

Haj*_*erg 5 android android-layout android-drawable material-design

我有一个列表项的布局,如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/spacing_very_small"
    android:layout_marginEnd="@dimen/spacing_large"
    android:layout_marginStart="64dp"
    android:layout_marginTop="@dimen/spacing_very_small">


    <LinearLayout
        android:minWidth="100dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_alignParentEnd="true"
        android:background="@drawable/red_bubble"
        android:gravity="end"
        android:layout_margin="8dp"
        android:elevation="4dp"
        >

        <TextView
            android:id="@+id/content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:lineSpacingMultiplier="1.1"
            android:paddingTop="@dimen/spacing_normal"
            android:paddingBottom="@dimen/spacing_small"
            android:paddingStart="@dimen/spacing_normal"
            android:paddingEnd="@dimen/spacing_normal"
            android:textColor="@color/white"
            android:text="TEST"/>

        <TextView
            android:id="@+id/date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="12dp"
            android:gravity="end"
            android:paddingStart="@dimen/spacing_normal"
            android:paddingEnd="@dimen/spacing_normal"
            android:paddingBottom="@dimen/spacing_normal"
            android:textColor="@color/white"
            android:text="yesterday"/>

    </LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

而 LinearLayout 的背景是一个带有红色和圆形边缘的形状:

<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <solid android:color="@color/red"/>

    <corners android:bottomRightRadius="5dp" android:bottomLeftRadius="20dp"
    android:topLeftRadius="5dp" android:topRightRadius="5dp" />

</shape>
Run Code Online (Sandbox Code Playgroud)

问题是,当所有边缘具有相同的半径时,为什么仰角有效,并且有阴影,但是当我更改其中一个角度(在这种情况下为左下角)的半径时,阴影消失了?

测试

这个问题有解决方案吗?

Mat*_*uno 0

您可能可以通过设置 ViewOutlineProvider 并通过路径传递相同的形状来取回它。