【发布时间】:2018-11-14 12:11:39
【问题描述】:
您好,我在我的应用程序中使用卡片视图创建了一个家庭仪表板设计,问题是,在 api 21 (Android 5.1) 中卡片视图不显示。我尝试将硬件加速放在 android manifest 中,但仍然无法正常工作。这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f2f9ff"
tools:context=".activity.MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="385dp"
android:layout_height="273dp"
android:scaleType="centerCrop"
app:srcCompat="@drawable/header_img"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="29dp"
app:srcCompat="@drawable/ukssssssss"
tools:layout_editor_absoluteX="142dp"
tools:layout_editor_absoluteY="93dp" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView2"
android:layout_centerHorizontal="true"
android:text="UKS TK CENDEKIA HARAPAN"
android:textColor="#fff"
tools:layout_editor_absoluteX="102dp"
tools:layout_editor_absoluteY="193dp" />
<GridLayout
android:id="@+id/mainGrid"
android:layout_width="383dp"
android:layout_height="293dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView3"
android:layout_marginTop="35dp"
android:layout_weight="8"
android:alignmentMode="alignMargins"
android:columnCount="2"
android:padding="14dp"
android:rowCount="2"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="239dp">
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_rowWeight="1"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:layout_width="125dp"
android:layout_height="55dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/medicalrecord"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medical Record"
android:textColor="@android:color/black"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_rowWeight="1"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:layout_width="125dp"
android:layout_height="55dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/plant" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nusantara Plants"
android:textColor="@android:color/black"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_rowWeight="1"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:layout_width="125dp"
android:layout_height="55dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/healingtherapy" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Healing Therapy"
android:textColor="@android:color/black"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_rowWeight="1"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:layout_width="125dp"
android:layout_height="55dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/calendaricon"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="What's Going On?"
android:textAlignment="center"
android:textColor="@android:color/black"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
</android.support.v7.widget.CardView>
</GridLayout>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:text="Indonesia Sehat"
android:textColor="#fff"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
尝试了不同的 android 版本,但它可以工作,而且当我在设计视图中将其更改为 api 21 时,它也显示黑色卡片视图而不是白色卡片视图。 this link上的问题没有解决我的问题,他们要求解决卡片提升,而不是卡片视图不显示
【问题讨论】:
-
请看我的编辑,谢谢,顺便说一句,它不能解决我的问题@VishvaDave
-
卡不显示是什么意思。如果没有海拔,你看不到任何卡。它将显示为正常布局。所以基本上你的卡可以工作,但阴影不是在那里所以它看起来像一个正常的..所以尝试这个解决方案一次
-
我在卡片视图中添加了海拔@VishvaDave
-
看我的回答@TimothyDillan
标签: java android android-studio android-cardview android-gridview