我试图在我的应用程序中制作一个CardView但我的主要问题是,当它在模拟器(API27)上正确显示时,带有API21的cardView没有显示在我的手机上。
我不熟悉android,所以我无法解决问题所在,我该如何解决。
这是在模拟器和电话中看起来像的图片 虽然这是我的布局的XML代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/rellay_LOAD"
android:alignmentMode="alignMargins"
android:columnCount="2"
android:columnOrderPreserved="false"
android:rowCount="4">
<!-- Row 1 -->
<!--Column 1 -->
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="2dp"
android:layout_marginEnd="2dp"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_rowWeight="1"
app:cardElevation="0.50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CAFFE"
android:textAlignment="center"
android:textColor="@android:color/black"
tools:ignore="HardcodedText" />
</LinearLayout>
</android.support.v7.widget.CardView>
<!--Column 2 -->
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="2dp"
android:layout_marginEnd="2dp"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_rowWeight="1"
app:cardElevation="0.50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CAFFE"
android:textAlignment="center"
android:textColor="@android:color/black"
tools:ignore="HardcodedText" />
</LinearLayout>
</android.support.v7.widget.CardView>
<!-- Row 2 -->
<!--Column 1 -->
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="2dp"
android:layout_marginEnd="2dp"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_rowWeight="1"
app:cardElevation="0.50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CAFFE"
android:textAlignment="center"
android:textColor="@android:color/black"
tools:ignore="HardcodedText" />
</LinearLayout>
</android.support.v7.widget.CardView>
<!--Column 2 -->
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="2dp"
android:layout_marginEnd="2dp"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_rowWeight="1"
app:cardElevation="0.50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CAFFE"
android:textAlignment="center"
android:textColor="@android:color/black"
tools:ignore="HardcodedText" />
</LinearLayout>
</android.support.v7.widget.CardView>
<!-- Row 3 -->
<!--Column 1 -->
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="2dp"
android:layout_marginEnd="2dp"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_rowWeight="1"
app:cardElevation="0.50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CAFFE"
android:textAlignment="center"
android:textColor="@android:color/black"
tools:ignore="HardcodedText" />
</LinearLayout>
</android.support.v7.widget.CardView>
<!--Column 2 -->
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="2dp"
android:layout_marginEnd="2dp"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_rowWeight="1"
app:cardElevation="0.50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CAFFE"
android:textAlignment="center"
android:textColor="@android:color/black"
tools:ignore="HardcodedText" />
</LinearLayout>
</android.support.v7.widget.CardView>
<!-- Row 4 -->
<!--Column 1 -->
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="2dp"
android:layout_marginEnd="2dp"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_rowWeight="1"
app:cardElevation="0.50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CAFFE"
android:textAlignment="center"
android:textColor="@android:color/black"
tools:ignore="HardcodedText" />
</LinearLayout>
</android.support.v7.widget.CardView>
<!--Column 2 -->
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="2dp"
android:layout_marginEnd="2dp"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_rowWeight="1"
app:cardElevation="0.50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CAFFE"
android:textAlignment="center"
android:textColor="@android:color/black"
tools:ignore="HardcodedText" />
</LinearLayout>
</android.support.v7.widget.CardView>
</GridLayout>
<RelativeLayout
android:id="@+id/rellay_LOAD"
android:layout_width="match_parent"
android:layout_height="97dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_centerInParent="true"
android:layout_weight="0.65"
android:background="@color/colorWhite"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
tools:ignore="NestedWeights,ObsoleteLayoutParam">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
tools:ignore="UselessParent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:text="CREATE"
android:textSize="14sp"
tools:ignore="HardcodedText" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>