应用程序不显示低于 Marshmallow 的任何内容。在 Marshmallow 及以上版本中效果很好

App doesn't show anything in lower than Marshmallow. In Marshmallow and above it works fine

我正在使用 Gridlayout 构建 ImageView 和 TextView 的图块。该应用程序在 Android 6.0 上运行良好。但在低于 6.0 的版本上,该应用程序只显示空白屏幕。请帮帮我。谢谢

这是 xml 文件。

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context="com.example.mrvirk.urduapp.MainActivity"
android:weightSum="8">


<GridLayout


    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnCount="2"
    android:rowCount="4">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:background="@color/green3"
        android:orientation="vertical"
        android:gravity="center"
        android:layout_margin="1dp"
        >

            <ImageView
                android:id="@+id/learning"
                android:layout_width="match_parent"
                android:layout_height="@android:dimen/notification_large_icon_width"
                android:scaleType="fitCenter"
                android:src="@drawable/learning"
                android:layout_gravity="center"
                />


        <TextView
            android:id="@+id/txtLearning"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Learning"
            android:textColor="@color/white"
            android:textStyle="bold" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:background="@color/yellow"
        android:orientation="vertical"
        android:gravity="center"
        android:layout_margin="1dp"
        >


            <ImageView
                android:id="@+id/acheivements"
                android:layout_width="match_parent"
                android:layout_height="@android:dimen/notification_large_icon_width"
                android:scaleType="fitCenter"
                android:src="@drawable/acheivements"

                />


        <TextView
            android:id="@+id/txtAcheivements"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Acheivements"
            android:textColor="@color/white"
            android:textStyle="bold" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_columnSpan="2"
        android:layout_rowWeight="1"
        android:layout_columnWeight="1"
        android:background="@color/red"
        android:orientation="vertical"
        android:gravity="center"
        android:layout_margin="1dp"
        >

        <ImageView
            android:id="@+id/quiz"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitCenter"
            android:src="@drawable/quiz" />

        <TextView
            android:id="@+id/txtQuiz"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Quiz"
            android:textColor="@color/white"
            android:textStyle="bold" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:background="@color/blue2"
        android:orientation="vertical"
        android:gravity="center"
        android:layout_margin="1dp"
        >

        <ImageView
            android:id="@+id/setting"
            android:layout_width="match_parent"
            android:layout_height="@android:dimen/notification_large_icon_width"
            android:scaleType="fitCenter"
            android:src="@drawable/setting" />

        <TextView
            android:id="@+id/txtSetting"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Setting"
            android:textColor="@color/white"
            android:textStyle="bold" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:background="@color/tea"
        android:orientation="vertical"
        android:gravity="center"
        android:layout_margin="1dp"
        >

        <ImageView
            android:id="@+id/share"
            android:layout_width="match_parent"
            android:layout_height="@android:dimen/notification_large_icon_width"
            android:scaleType="fitCenter"
            android:src="@drawable/share" />

        <TextView
            android:id="@+id/txtshare"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Share"
            android:textColor="@color/white"
            android:textStyle="bold" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:background="@color/org"
        android:orientation="vertical"
        android:gravity="center"
        android:layout_margin="1dp"
        >

        <ImageView
            android:id="@+id/about"
            android:layout_width="match_parent"
            android:layout_height="@android:dimen/notification_large_icon_width"
            android:scaleType="fitCenter"
            android:src="@drawable/about" />

        <TextView
            android:id="@+id/txtAbout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="About"
            android:textColor="@color/white"
            android:textStyle="bold" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:background="@color/green3"
        android:orientation="vertical"
        android:gravity="center"
        android:layout_margin="1dp"
        >

        <ImageView
            android:id="@+id/moreApps"
            android:layout_width="match_parent"
            android:layout_height="@android:dimen/notification_large_icon_width"
            android:scaleType="fitCenter"
            android:src="@drawable/moreapps" />

        <TextView
            android:id="@+id/txtMoreApps"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="More Apps"
            android:textColor="@color/white"
            android:textStyle="bold" />

    </LinearLayout>
</GridLayout>

这是模拟器上的视图。在真机上还是一样。

Gradle 文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    defaultConfig {
        applicationId "com.example.mrvirk.urduapp"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:21.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'

您使用的属性如下:

    android:layout_columnWeight="1"
    android:layout_rowWeight="1"

仅适用于 api>=21

确保您的 gradle 中有:

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:gridlayout-v7:27.1.1'

或更高版本
并在 xml 中将 GridLayout 标签替换为

android.support.v7.widget.GridLayout