【问题标题】:Elevation on a layout which has a shape drawable background with different corner radii具有不同角半径的可绘制形状背景的布局上的标高
【发布时间】:2018-04-02 11:05:00
【问题描述】:

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

<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>

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>

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

这个问题有解决办法吗?

【问题讨论】:

  • 尝试将您的形状指定为矩形而不是不指定,看看它在您的形状中是否像这样工作&lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" &gt;
  • 遗憾的是,它并没有改变任何东西。
  • 你为什么不使用卡片视图而忘记在线性布局中设置的这个令人厌烦的高度,因为我确信 CardView 总是有效的

标签: android android-layout material-design android-drawable


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2011-12-23
    • 1970-01-01
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    • 2022-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多