In the project I am using cardviews inside ConstraintLayout inside a recyclerview viewholder/item. It is showing normally in the android studio preview, but when i run the project in the phone or emulator, the cardview's shadow is not shown and the imageview inside the cardview is not clipped as well.
This layout is shown as just a normal flat layout without any kind of shadows or clipping. How can i resolve this..?
layout.xml
<androidx.constraintlayout.widget.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:id="@+id/parentLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/c_FFFFFF_white"
android:padding="@dimen/dimen_8">
<!--<FrameLayout
android:id="@+id/linearLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dimen_34"
android:layout_marginTop="@dimen/dimen_24"
android:layout_marginEnd="@dimen/dimen_24"
android:layout_marginBottom="@dimen/dimen_24"
android:background="@drawable/bg_rounded_corner_with_shadow"
android:clipChildren="true"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">-->
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dimen_34"
android:layout_marginTop="@dimen/dimen_24"
android:layout_marginEnd="@dimen/dimen_24"
android:layout_marginBottom="@dimen/dimen_24"
android:clipChildren="true"
android:clipToPadding="true"
app:cardCornerRadius="@dimen/dimen_8"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dimen_60dp"
android:orientation="horizontal">
<com.example.ui.widgets.appWidgets.AppTextView
android:id="@+id/titleTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginStart="@dimen/dimen_24"
android:layout_marginEnd="@dimen/dimen_24"
android:maxLines="1"
android:textColor="@color/black"
android:textSize="@dimen/text_size_12"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/linkImageView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.example.ui.widgets.appWidgets.AppImageView
android:id="@+id/linkImageView"
android:layout_width="70dp"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@color/black_overlay"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<!-- </FrameLayout>-->
<com.example.ui.widgets.custom.FontIconTextView
android:id="@+id/fontIconTextView"
android:layout_width="@dimen/dimen_32"
android:layout_height="@dimen/dimen_32"
android:background="@drawable/bg_circle_icon_font"
android:elevation="@dimen/dimen_16"
app:layout_constraintBottom_toTopOf="@+id/cardView"
app:layout_constraintEnd_toStartOf="@+id/cardView"
app:layout_constraintStart_toStartOf="@+id/cardView"
app:layout_constraintTop_toTopOf="@+id/cardView" />
</androidx.constraintlayout.widget.ConstraintLayout>
style.xml
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.Bridge">
<item name="colorPrimary">@color/c_F5FCF9_cyan</item>
<item name="colorPrimaryDark">@color/c_F5FCF9_cyan</item>
<item name="colorAccent">@color/c_39B0E5_blue</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.example"
minSdkVersion 23
targetSdkVersion 29
versionCode 4967
versionName "3.0.0"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
debuggable false
multiDexEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
compileOptions {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
sourceSets {
main {
res.srcDirs =
[
'src/main/res',
'src/main/res/layouts/login',
'src/main/res/layouts/dialog',
'src/main/res/layouts/learning',
'src/main/res/layouts/common',
'src/main/res/layouts/sideMenu',
'src/main/res/layouts/exercise',
'src/main/res/layouts/quiz',
'src/main/res/layouts/feedback',
'src/main/res/layouts/adapter',
'src/main/res/layouts/discussion',
'src/main/res/layouts/template',
'src/main/res/layouts/points',
'src/main/res/layouts/submission',
'src/main/res/layouts/team',
'src/main/res/layouts/audio',
'src/main/res/layouts/external',
'src/main/res/layouts/downloads',
'src/main/res/layouts/announcement',
'src/main/res/layouts'
]
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
}
}
kapt {
generateStubs = true
}
androidExtensions {
experimental = true
}
packagingOptions {
pickFirst 'META-INF/*'
exclude 'META-INF/atomicfu.kotlin_module'
exclude 'META-INF/MANIFEST.MF'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation "com.android.support:exifinterface:29.1.0"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$rootProject.retrofitVersion"
implementation "com.squareup.retrofit2:adapter-rxjava2:2.6.1"
// reactive
implementation "io.reactivex.rxjava2:rxjava:$rootProject.rxjava2Version"
//noinspection GradleDependency
implementation "io.reactivex.rxjava2:rxandroid:$rootProject.rxandroidVersion"
implementation 'com.squareup.okhttp3:logging-interceptor:4.4.0'
implementation 'com.squareup.okhttp3:okhttp-urlconnection:4.4.0'
implementation 'com.squareup.okhttp3:okhttp:4.4.0'
// Facebook Login only
implementation 'com.facebook.android:facebook-login:5.15.3'
// google play
implementation 'com.google.android.gms:play-services-auth:18.1.0'
//glide
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
//JWPlayer
implementation 'com.longtailvideo.jwplayer:jwplayer-core:3.6.0'
implementation 'com.longtailvideo.jwplayer:jwplayer-common:3.6.0'
//Youtube Player ====> https://github.com/PierfrancescoSoffritti/android-youtube-player
implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:10.0.4'
//Firebase
implementation 'com.google.firebase:firebase-analytics:17.4.4'
//Pusher
implementation 'com.pusher:pusher-java-client:2.0.2'
//Amazon S3
implementation('com.amazonaws:aws-android-sdk-mobile-client:2.15.+@aar') { transitive = true }
implementation 'com.amazonaws:aws-android-sdk-s3:2.15.2'
implementation 'com.amazonaws:aws-android-sdk-core:2.15.2'
implementation 'com.amazonaws:aws-android-sdk-cognito:2.7.+'
//In-App Updates
// This dependency is downloaded from the Google’s Maven repository.
// So, make sure you also include that repository in your project's build.gradle file.
implementation 'com.google.android.play:core:1.6.5'
//Kotlin coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
//Room DB
implementation "androidx.room:room-runtime:$rootProject.roomVersion"
implementation "androidx.room:room-ktx:$rootProject.roomVersion"
kapt "androidx.room:room-compiler:$rootProject.roomVersion"
androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"
//viewmodel extension
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$rootProject.archLifecycleVersion"
implementation "org.jsoup:jsoup:1.12.1"
debugImplementation 'im.dino:dbinspector:4.0.0'
}
The issue is fixed now. For some reason I had
android:hardwareAccelerated="false"
for the activity. I removed this line and the issue resolved.