api 22及以下版本未显示Android CardView

时间:2019-07-02 13:23:56

标签: android android-cardview

我有一个xml布局,它使用cardViews的概念来显示按钮。它仅适用于api 23及更高版本,但仅适用于api 22及更低版本,cardView按钮不会出现。我曾尝试研究此问题,但对我而言仍然没有任何效果。

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:background="@drawable/bg"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <RelativeLayout
        android:layout_weight="2"
        android:layout_width="match_parent"
        android:layout_height="0dp">
        <TextView
            android:id="@+id/textGrid"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:fontFamily="@font/muli_extrabold"
            android:padding="10dp"
            android:text="Voice of Faith"
            android:textAlignment="center"
            android:textColor="@android:color/white"
            android:textSize="28sp" />

    </RelativeLayout>
   <GridLayout
        android:id="@+id/mainGrid"
        android:columnCount="2"
        android:rowCount="3"
        android:alignmentMode="alignMargins"
        android:columnOrderPreserved="false"
        android:layout_weight="8"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:padding="14dp">

        <!-- Row 1 -->

        <!-- Column 1 -->
        <androidx.cardview.widget.CardView
            android:id="@+id/adult_devotional"
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:focusable="true"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">

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


                <TextView
                    android:text="Adult Devotional"
                    android:textAlignment="center"
                    android:textColor="@color/customTextColor"
                    android:textSize="14sp"
                    android:fontFamily="@font/muli_extrabold"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </androidx.cardview.widget.CardView>

        <!-- Column 2 -->
        <androidx.cardview.widget.CardView
            android:id="@+id/children_devotional"
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:focusable="true"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">

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

                <TextView
                    android:text="Children Devotional"
                    android:textAlignment="center"
                    android:textColor="@color/customTextColor"
                    android:textSize="14sp"
                    android:fontFamily="@font/muli_extrabold"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </androidx.cardview.widget.CardView>


        <!-- Row 2 -->

        <!-- Column 1 -->
        <androidx.cardview.widget.CardView
            android:id="@+id/daily_mass"
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:focusable="true"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Daily Mass Readings"
                    android:textAlignment="center"
                    android:textSize="14sp"
                    android:textColor="@color/customTextColor"
                    android:fontFamily="@font/muli_extrabold" />

            </LinearLayout>

        </androidx.cardview.widget.CardView>

        <!-- Column 2 -->
        <androidx.cardview.widget.CardView
            android:id="@+id/order_mass"
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:focusable="true"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">

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

                <TextView
                    android:text="The Order of Mass"
                    android:textAlignment="center"
                    android:textSize="14sp"
                    android:textColor="@color/customTextColor"
                    android:fontFamily="@font/muli_extrabold"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </androidx.cardview.widget.CardView>


        <!-- Row 2 -->

        <!-- Column 1 -->
        <androidx.cardview.widget.CardView
            android:id="@+id/hours"
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:focusable="true"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">

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

                <TextView
                    android:text="Hours"
                    android:textAlignment="center"
                    android:textSize="14sp"
                    android:textColor="@color/customTextColor"
                    android:fontFamily="@font/muli_extrabold"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </androidx.cardview.widget.CardView>

        <!-- Column 2 -->
        <androidx.cardview.widget.CardView
            android:id="@+id/other_prayers"
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:focusable="true"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">

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


                <TextView
                    android:text="Other Prayers"
                    android:textAlignment="center"
                    android:textSize="14sp"
                    android:textColor="@color/customTextColor"
                    android:fontFamily="@font/muli_extrabold"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:id="@+id/profile"
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:focusable="true"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">

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

                    android:text="Account/Profile"
                    android:textAlignment="center"
                    android:textSize="14sp"
                    android:textColor="@color/customTextColor"
                    android:fontFamily="@font/muli_extrabold"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:id="@+id/feedback"
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:focusable="true"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">

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


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:textSize="14sp"
                    android:fontFamily="@font/muli_extrabold"
                    android:textColor="@color/customTextColor"
                    android:text="Feedback"
                    android:textAlignment="center"/>

            </LinearLayout>

        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:id="@+id/news"
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:focusable="true"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">
            <LinearLayout
                android:layout_gravity="center_horizontal|center_vertical"
                android:layout_margin="16dp"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:fontFamily="@font/muli_extrabold"
                    android:text="Editing/Publishing"
                    android:textAlignment="center"
                    android:textSize="14sp"
                    android:textColor="@color/customTextColor" />

            </LinearLayout>

        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:id="@+id/share_app"
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:focusable="true"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">

            <LinearLayout
                android:layout_gravity="center_horizontal|center_vertical"
                android:layout_margin="16dp"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">    
                <TextView
                    android:text="Share App"
                    android:textAlignment="center"
                    android:textSize="14sp"
                    android:textColor="@color/customTextColor"
                    android:fontFamily="@font/muli_extrabold"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </androidx.cardview.widget.CardView>

    </GridLayout>
</LinearLayout>

Build.Gradle

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    implementation 'co.paystack.android:paystack:3.0.10'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.hbb20:ccp:2.2.3'
    implementation 'com.google.firebase:firebase-firestore:18.1.0'
    implementation 'com.braintreepayments:card-form:3.1.1'
    implementation 'com.firebaseui:firebase-ui-database:0.4.0'
    implementation 'com.github.bumptech.glide:glide:4.7.1'
    implementation 'com.google.firebase:firebase-storage:15.0.0'
    implementation 'com.android.support:gridlayout-v7:28.0.0'
    implementation 'com.google.firebase:firebase-auth:16.1.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation 'com.github.ybq:Android-SpinKit:1.2.0'
    implementation 'com.google.firebase:firebase-crash:16.2.1'
    implementation 'com.google.firebase:firebase-config:16.3.0'
    implementation 'com.google.firebase:firebase-database:16.1.0'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'com.google.firebase:firebase-messaging:17.4.0'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
apply plugin: 'com.google.gms.google-services'

0 个答案:

没有答案