【问题标题】:Shadow behind a cardview using xml使用xml的cardview背后的阴影
【发布时间】:2017-02-23 05:30:07
【问题描述】:

我正在尝试制作一个带有阴影的圆形图像视图。我搜索了很多地方,但到处都是使用 java 或任何其他方法,但它们似乎都不适合我。有没有办法使用xml来做到这一点。请帮帮我。

这是我的图像视图:

        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:tint="#fff"
            android:padding="12dp"
            card_view:srcCompat="@drawable/ic_add_shopping_cart_black_24dp"
            android:background="@drawable/cart_shape"
            android:id="@+id/image"
            android:layout_alignTop="@+id/food"
            android:layout_alignStart="@+id/price" />

这是我的drawable形状:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="1dp"
android:shape="ring"
android:thicknessRatio="2.5"
android:useLevel="false" >

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

<stroke
    android:width="1dp"
    android:color="@color/colorPrimary" />
<solid
    android:color="@color/colorPrimary"
    />
<padding
    android:left="6dp"
    android:top="6dp"
    android:right="6dp"
    android:bottom="6dp"
    />
</shape>

【问题讨论】:

  • 可以使用android:elevation属性
  • 试过了,不行..
  • 你想要什么样的阴影?

标签: java android xml imageview


【解决方案1】:

在图像视图中使用android:elevation。 根据值阴影会变化。

【讨论】:

    【解决方案2】:

    只需添加

    card_view:cardUseCompatPadding="true"

    到您的 CardView

    【讨论】:

      【解决方案3】:

      您可以使用android:elevation 属性来实现您想要的。

      您可以在此处阅读更多有关 Android evevations 的信息。
      https://material.io/guidelines/material-design/elevation-shadows.html

      【讨论】:

        猜你喜欢
        • 2021-10-01
        • 2018-08-11
        • 2018-01-18
        • 2018-12-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多