Я постараюсь быть кратким. Когда я запускаю свое приложение на некоторых устройствах, у меня возникают проблемы с расположением CardView. Я думаю, что это происходит со старыми устройствами. Я добавляю ниже изображения, в первых двух проблема не существует, в двух других да.
Я пробовал все, в студии Android он показывает правильно со всеми API (20-29) java код не был изменен.
Samsung j5 2016:
Xiaomi Redmi 5 Plus :
Планшет Lenovo:
Wiko Rainbow lite:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="@color/dracula"
tools:context=".Capitoli">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_marginTop="32dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/text"
android:text="hi"
android:textSize="24sp"
android:textColor="#FFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_marginTop="6dp"
android:layout_below="@+id/text"
android:text="58 "
android:textSize="14sp"
android:textColor="#FFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:layout_alignParentRight="true"
android:layout_width="62dp"
android:layout_height="62dp"
android:src="@drawable/tomato"/>
</RelativeLayout>
<GridLayout
android:columnCount="2"
android:rowCount="3"
android:alignmentMode="alignMargins"
android:columnOrderPreserved="false"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp">
<LinearLayout
android:orientation="vertical"
android:padding="16dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="@drawable/whale"
android:layout_width="80dp"
android:layout_height="80dp"/>
<TextView
android:textColor="@color/viola"
android:textSize="18sp"
android:text="capitolo 1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp">
<LinearLayout
android:orientation="vertical"
android:padding="16dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="@drawable/whale"
android:layout_width="80dp"
android:layout_height="80dp"/>
<TextView
android:textColor="@color/viola"
android:textSize="18sp"
android:text="capitolo 1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</GridLayout>
</LinearLayout>
</ScrollView>