android - Cardview 突然停止显示阴影

标签 android android-studio android-layout out-of-memory

如何显示cardview elevation if

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

最佳答案

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

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

这样你就可以离开 android:hardwareAccelerated="false"未使用卡片 View 且应用程序级别标记为 true 的 Activity 。

关于android - Cardview 突然停止显示阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57459907/

相关文章:

java - Android 中 ZIP 文件夹中的基本名称是什么?

android - React Navigation - 在 Blurview 中包装标题和选项卡导航器会丢失 Prop

android-studio - 无法在 AMD 上运行 Android Studio 模拟器 - 错误 : x86

java - 如何让ZXing在android中的部分 Activity (而不是全屏)中显示?

android - 如何以编程方式将具有背景颜色和权重的 LinearLayout 添加到另一个布局

android - 如何使用 xml 按钮以编程方式禁用按钮

android - 在android上绘制非矩形形状

android - 填充在某些设备上不起作用

java - 尝试在空对象引用上调用虚拟方法(JAVA、AS)

Android:requestLayout() 调用不当