我在 RecyclerView 中使用 CardView。
经过大量阅读后,我最终只在 Android 5.1.1 上遵循“不工作”代码。在之前的 Android 版本上,它运行良好。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#11ffffff"
android:orientation="vertical"
android:paddingBottom="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#11ffffff">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@color/primary_bg_light"
card_view:cardCornerRadius="2dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primary_bg_light">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingBottom="15dp"
android:paddingLeft="15dp"
android:textColor="@color/background_floating_material_light"
android:textSize="24sp"
android:textStyle="bold" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
</LinearLayout>
我也尝试使用代码设置海拔,但结果相同。
为了使其兼容 api 21 以上或以下,您需要在支持 CardView 中指定 app:cardUseCompatPadding="true"。
<android.support.v7.widget.CardView
app:cardElevation="4dp"
app:cardUseCompatPadding="true"
app:cardMaxElevation="6dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.CardView>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)