首页 > 解决方案 > Cardview 突然停止显示阴影

问题描述

如果如何显示卡片视图高度

android:hardwareAccelerated="false"

AndroidManifest.xml中

我的应用程序配置是

    <application
    android:name="MyappApplication"
    android:allowBackup="true"
    android:hardwareAccelerated="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher"
    android:supportsRtl="true"
    android:largeHeap="true"
    android:theme="@style/AppTheme"
    android:usesCleartextTraffic="true">

我的 CardView 是

 <androidx.cardview.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginStart="@dimen/spacing_small"
    android:layout_marginEnd="@dimen/spacing_small"
    card_view:cardBackgroundColor="@color/white"
    android:foreground="?android:attr/selectableItemBackground"
    android:outlineAmbientShadowColor="@color/colorPrimaryDark"
    android:outlineSpotShadowColor="@color/colorPrimaryDark"
    card_view:cardCornerRadius="@dimen/spacing_small"
    card_view:cardElevation="2dp"
    card_view:cardUseCompatPadding="true"
    tools:ignore="UnusedAttribute">

标签: androidandroid-studioandroid-layoutout-of-memory

解决方案


我认为不可能用 android:hardwareAccelerated="false". 如果在您的应用程序中绝对有必要,一种解决方案可能是通过活动而不是应用程序级别设置加速。

<activity ... /> <activity android:hardwareAccelerated="" />

这样,您可以将android:hardwareAccelerated="false"未使用卡片视图的活动保留为未使用的活动,并将应用程序级别标记保留为 true。


推荐阅读