Android 4.4 去除CardView的阴影
Android 4.4 remove shadow from CardView
我试图从 Cardview 中删除阴影。
我在 android v4.4.2
上使用 android 支持 v7 Cardview
我的布局外观:
<android.support.v7.widget.CardView
android:id="@+id/cardContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
card_view:cardBackgroundColor="@color/transparent"
card_view:cardCornerRadius="0dp"
card_view:cardElevation="0dp"
card_view:cardPreventCornerOverlap="false"
card_view:contentPadding="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/include_profile_header" />
<include layout="@layout/include_profile_footer" />
</RelativeLayout>
</android.support.v7.widget.CardView>
如你所见,我使用了:
card_view:cardElevation="0dp"
到目前为止已尝试:
android:background="@null"
但是你仍然可以在图像中看到我附上了显示的顶部阴影。
在 4.4 中无法去除 cardview 的阴影。海拔低于 5.0 的任何东西都没有任何作用,所以 4.4 中的所有 cardview 都是带有阴影的图像
To create a card with a shadow, use the card_view:cardElevation
attribute. CardView uses real elevation and dynamic shadows on Android
5.0 (API level 21) and above and falls back to a programmatic shadow implementation on earlier versions. For more information, see
Maintaining Compatibility.
http://developer.android.com/training/material/lists-cards.html#CardView
我只是改用相对布局解决了这个问题。只需将 CardView 值更改为相对布局,您基本上会得到相同的结果,但没有阴影
只需将以下代码添加到 cardview 标签中
app:cardElevation="0dp"
别忘了添加
xmlns:app="http://schemas.android.com/apk/res-auto"
更新
也试试把下面的代码放在 cardview 中
app:cardElevation="0dp"
app:cardMaxElevation="0dp"
app:cardCornerRadius="1dp"
app:cardUseCompatPadding="true"
app:cardPreventCornerOverlap="false"
android:background="@null"
app:cardCornerRadius
应该大于 0(>0) 否则抛出异常
我正在使用 API 28 支持库
implementation 'com.android.support:cardview-v7:28.0.0'
我试图从 Cardview 中删除阴影。
我在 android v4.4.2
我的布局外观:
<android.support.v7.widget.CardView
android:id="@+id/cardContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
card_view:cardBackgroundColor="@color/transparent"
card_view:cardCornerRadius="0dp"
card_view:cardElevation="0dp"
card_view:cardPreventCornerOverlap="false"
card_view:contentPadding="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/include_profile_header" />
<include layout="@layout/include_profile_footer" />
</RelativeLayout>
</android.support.v7.widget.CardView>
如你所见,我使用了:
card_view:cardElevation="0dp"
到目前为止已尝试:
android:background="@null"
但是你仍然可以在图像中看到我附上了显示的顶部阴影。
在 4.4 中无法去除 cardview 的阴影。海拔低于 5.0 的任何东西都没有任何作用,所以 4.4 中的所有 cardview 都是带有阴影的图像
To create a card with a shadow, use the card_view:cardElevation attribute. CardView uses real elevation and dynamic shadows on Android 5.0 (API level 21) and above and falls back to a programmatic shadow implementation on earlier versions. For more information, see Maintaining Compatibility.
http://developer.android.com/training/material/lists-cards.html#CardView
我只是改用相对布局解决了这个问题。只需将 CardView 值更改为相对布局,您基本上会得到相同的结果,但没有阴影
只需将以下代码添加到 cardview 标签中
app:cardElevation="0dp"
别忘了添加
xmlns:app="http://schemas.android.com/apk/res-auto"
更新
也试试把下面的代码放在 cardview 中
app:cardElevation="0dp"
app:cardMaxElevation="0dp"
app:cardCornerRadius="1dp"
app:cardUseCompatPadding="true"
app:cardPreventCornerOverlap="false"
android:background="@null"
app:cardCornerRadius
应该大于 0(>0) 否则抛出异常
我正在使用 API 28 支持库
implementation 'com.android.support:cardview-v7:28.0.0'