网格布局和CardView未显示在旧的Android设备上

问题描述 投票:0回答:1

我正在寻找解决方案。使用cardView的Grid Layout可以很好地显示在最新的设备上,但是较旧的设备(如Lollipop)和其他一些Android设备版本则不会显示Grid Layout和CardView。请给我解决方案,好像我可以建立我的项目。谢谢

这是我的布局代码

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:name="com.facebook.ads.AudienceNetworkActivity"
    android:hardwareAccelerated="true"
    tools:context=".MainActivity">


    <View
        android:layout_width="match_parent"
        android:layout_height="230dp"
        android:id="@+id/bg_top_header"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:background="@drawable/ic_bg_topheader"/>

    <ImageView
        android:id="@+id/user_photo"
        android:layout_width="71dp"
        android:layout_height="71dp"
        android:layout_marginStart="26dp"
        android:layout_marginTop="24dp"
        android:src="@mipmap/ic_launcher"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginLeft="26dp" />

    <TextView
        android:textSize="20sp"
        android:text="বাংলা ইসলামিক "
        android:id="@+id/user_name"
        android:textColor="#ffffff"
        android:fontFamily="@font/mo_re"
        android:layout_marginTop="30dp"
        android:layout_marginStart="18dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toEndOf="@id/user_photo"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginLeft="18dp" />

    <TextView
        android:textSize="16sp"
        android:text="নিউজ পোর্টাল"
        android:id="@+id/user_id"
        android:fontFamily="@font/mo_re"
        android:textColor="#ffffff"
        android:layout_marginTop="32dp"
        android:layout_marginStart="18dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toEndOf="@id/user_photo"
        app:layout_constraintTop_toTopOf="@id/user_name"
        android:layout_marginLeft="18dp" />

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="110dp"
        android:layout_marginBottom="60dp"
        android:alignmentMode="alignMargins"
        android:columnCount="2"
        android:columnOrderPreserved="false"
        android:padding="14dp"
        android:rowCount="3"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="@id/bg_top_header"
        app:layout_constraintVertical_bias="0.0"
        app:layout_editor_absoluteX="0dp">

        <android.support.v7.widget.CardView
            android:clickable="true"
            android:id="@+id/btn_our_islam"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_rowWeight="1"
            android:layout_columnWeight="1"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginBottom="16dp"
            android:background="@color/cardColor"
            app:cardCornerRadius="8dp"
            app:cardElevation="6dp">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal|center_vertical"
                android:layout_margin="16dp"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="120dp"
                    android:layout_height="50dp"
                    android:layout_gravity="center_horizontal"
                    android:background="@drawable/ourislams" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/t_ourislam"
                    android:textColor="@color/textcardColor"
                    android:textSize="14sp"
                    android:layout_marginTop="8dp"
                    android:fontFamily="@font/mo_re"
                    android:textStyle="bold"/>
            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:clickable="true"
            android:id="@+id/btn_islam_times"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_rowWeight="1"
            android:layout_columnWeight="1"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginBottom="16dp"
            android:background="@color/cardColor"
            app:cardCornerRadius="8dp"
            app:cardElevation="6dp">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal|center_vertical"
                android:layout_margin="16dp"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="120dp"
                    android:layout_height="50dp"
                    android:layout_gravity="center_horizontal"
                    android:background="@drawable/islamtimes" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/t_islamtimes"
                    android:textColor="@color/textcardColor"
                    android:textSize="14sp"
                    android:layout_marginTop="8dp"
                    android:fontFamily="@font/mo_re"
                    android:textStyle="bold"/>
            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:clickable="true"
            android:id="@+id/btn_insaf"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_rowWeight="1"
            android:layout_columnWeight="1"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginBottom="16dp"
            android:background="@color/cardColor"
            app:cardCornerRadius="8dp"
            app:cardElevation="6dp">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal|center_vertical"
                android:layout_margin="16dp"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="120dp"
                    android:layout_height="50dp"
                    android:layout_gravity="center_horizontal"
                    android:background="@drawable/insaf"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/t_insaf"
                    android:textColor="@color/textcardColor"
                    android:textSize="14sp"
                    android:layout_marginTop="8dp"
                    android:fontFamily="@font/mo_re"
                    android:textStyle="bold"/>
            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:clickable="true"
            android:id="@+id/btn_patheo"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_rowWeight="1"
            android:layout_columnWeight="1"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginBottom="16dp"
            android:background="@color/cardColor"
            app:cardCornerRadius="8dp"
            app:cardElevation="6dp">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal|center_vertical"
                android:layout_margin="16dp"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="120dp"
                    android:layout_height="50dp"
                    android:layout_gravity="center_horizontal"
                    android:background="@drawable/patheo"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/t_patheo"
                    android:layout_marginTop="8dp"
                    android:textColor="@color/textcardColor"
                    android:textSize="14sp"
                    android:fontFamily="@font/mo_re"
                    android:textStyle="bold"/>
            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:clickable="true"
            android:id="@+id/btn_iab_news"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_rowWeight="1"
            android:layout_columnWeight="1"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginBottom="16dp"
            android:background="@color/cardColor"
            app:cardCornerRadius="8dp"
            app:cardElevation="6dp">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal|center_vertical"
                android:layout_margin="16dp"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="120dp"
                    android:layout_height="50dp"
                    android:layout_gravity="center_horizontal"
                    android:background="@drawable/iabnews"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/t_iab"
                    android:textColor="@color/textcardColor"
                    android:textSize="14sp"
                    android:layout_marginTop="8dp"
                    android:fontFamily="@font/mo_re"
                    android:textStyle="bold"/>
            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:clickable="true"
            android:id="@+id/btn_suggest"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_rowWeight="1"
            android:layout_columnWeight="1"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginBottom="16dp"
            android:background="@color/cardColor"
            app:cardCornerRadius="8dp"
            app:cardElevation="6dp">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal|center_vertical"
                android:layout_margin="16dp"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="120dp"
                    android:layout_height="50dp"
                    android:layout_gravity="center_horizontal"
                    android:background="@drawable/suggest"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="উপদেশ দিন"
                    android:layout_marginTop="8dp"
                    android:textColor="@color/textcardColor"
                    android:textSize="14sp"
                    android:fontFamily="@font/mo_re"
                    android:textStyle="bold"/>
            </LinearLayout>

        </android.support.v7.widget.CardView>








    </GridLayout>


    <LinearLayout
        android:id="@+id/banner_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        android:orientation="vertical"/>

</android.support.constraint.ConstraintLayout>

build.gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.tanbhirhossain.binp"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 10
        versionName "10.0.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    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'
    implementation 'com.facebook.android:audience-network-sdk:5.+'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:gridlayout-v7:28.0.0'
}
android android-layout android-cardview cardview
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.