while using grid layout and cardview it shows only white rectangle not even divided on my phone while working fine on the emulator, adding pics so you could see exactly what I'm talking about;
on the emulator it looks like this: pic from emulator
and on my phone it looks like this: pic from my phone:
this is the xml:
<RelativeLayout
android:layout_below="@+id/layoutGrid"
android:layout_width="match_parent"
android:layout_height="10dp"
android:id="@+id/space"
android:background="#000036"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/layoutMore"
android:layout_below="@+id/space"
android:background="#000036">
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:rowCount="1"
android:columnCount="3"
android:columnOrderPreserved="false"
android:alignmentMode="alignMargins">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_row="0"
android:layout_column="0"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:layout_row="0"
android:layout_column="0"
android:layout_gravity="center"
android:background="#126180"
android:id="@+id/layoutSettings">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/baseline_settings"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Settings"
android:textColor="@color/white"
android:layout_gravity="center"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp"
android:background="#000036">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:layout_gravity="center"
android:background="#000036"
android:id="@+id/layoutReports">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/baseline_square"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
app:cardElevation="6dp"
android:layout_row="0"
android:layout_column="2"
app:cardCornerRadius="12dp"
android:layout_margin="12dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:layout_gravity="center"
android:background="#126180"
android:id="@+id/layoutCalander">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/baseline_calendar"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calender"
android:textColor="@color/white"
android:layout_gravity="center"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</GridLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/layoutGrid"
android:layout_below="@+id/layoutMission">
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:rowCount="1"
android:columnCount="3"
android:columnOrderPreserved="false"
android:alignmentMode="alignMargins">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_row="0"
android:layout_column="0"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:layout_gravity="center"
android:background="#126180"
android:id="@+id/tvBooks">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/baseline_library_books"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Library"
android:layout_gravity="center"
android:textColor="@color/white"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_row="0"
android:layout_column="1"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:layout_gravity="center"
android:background="#126180"
android:id="@+id/notes">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/baseline_notes"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notes"
android:layout_gravity="center"
android:textColor="@color/white"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_row="0"
android:layout_column="2"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:layout_gravity="center"
android:background="#126180"
android:id="@+id/tvPhone">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/baseline_call_24"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone"
android:textColor="@color/white"
android:layout_gravity="center"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</GridLayout>
</LinearLayout>
</RelativeLayout>
Try This Code :-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/space"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/layoutGrid"
android:background="#000036"
android:orientation="vertical">
<LinearLayout
android:id="@+id/layoutGrid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
app:cardCornerRadius="12dp"
app:cardElevation="6dp">
<LinearLayout
android:id="@+id/tvBooks"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#126180"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_launcher_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Library"
android:textColor="@color/white" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
app:cardCornerRadius="12dp"
app:cardElevation="6dp">
<LinearLayout
android:id="@+id/notes"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#126180"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_launcher_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Notes"
android:textColor="@color/white" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
app:cardCornerRadius="12dp"
app:cardElevation="6dp">
<LinearLayout
android:id="@+id/tvPhone"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#126180"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_launcher_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Phone"
android:textColor="@color/white" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<LinearLayout
android:id="@+id/layoutMore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000036"
android:orientation="horizontal">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
app:cardCornerRadius="12dp"
app:cardElevation="6dp">
<LinearLayout
android:id="@+id/layoutSettings"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_row="0"
android:layout_column="0"
android:layout_gravity="center"
android:background="#126180"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_launcher_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Settings"
android:textColor="@color/white" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:background="#000036"
app:cardCornerRadius="12dp"
app:cardElevation="6dp">
<LinearLayout
android:id="@+id/layoutReports"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#000036"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
app:cardCornerRadius="12dp"
app:cardElevation="6dp">
<LinearLayout
android:id="@+id/layoutCalander"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#126180"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_launcher_background" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Calender"
android:textColor="@color/white" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>