Skip to content

alibardide5124/CardViewPlus

Repository files navigation

CardViewPlus

sample

Version API Codacy Badge

A library to make animated CardView elevation
Download sample app from here

Usage

Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Add the dependency

dependencies {
		implementation 'androidx.cardview:cardview:1.0.0'
        implementation 'com.github.alibardide5124:CardViewPlus:1.0.6'
}

Now you're ready to use CardViewPlus

You can use CardViewPlus just like a normal CardView

<com.alibardide5124.cardviewplus.CardViewPlus
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
	... >	
	
</com.alibardide5124.cardviewplus.CardViewPlus>

But it gives you some more attributes

Properties Type Default
normalCardElevation Dimension - Float (in code) 2dp
pressedCardElevation Dimension - Float (in code) 5dp
cardPressedColor Color cardBackgroundColor
animationEnabled Boolean true
clickDelay Int (milli second) 150

normalCardElevation : set CardViewPlus elevation in noraml state. Default: 2dp.

pressedCardElevation: set CardViewPlus elevation in pressed state. Default: 5dp.

If you want to disable elevation animation, set the same value for normalElevation and maxElevation.

cardPressedColor: set color for onTouch color animation. Default: #e0e0e0.

If you want to disable color animation, set the same value for pressedColor and cardBackgroundColor.

animationEnabled: enable or Disable CardViewPlus shadow and color animations. Default: true.

clickDelay: set a delay for click after release the CardViewPlus. Default: 150ms.

Suggest setting click delay more than 150ms.


Please use normalCardElevation and pressedCardElevation instead of cardElevation and maxCardElevation.


XML

<com.alibardide5124.cardviewplus.CardViewPlus
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	app:normalCardElevation="2dp"
	app:pressedCardElevation="5dp"
	app:cardPressedColor="#ffe0e0e0"
	app:animationEnabled="true"
	app:clickDelay="150">


</com.alibardide5124.cardviewplus.CardViewPlus>

Kotlin

cardViewPlus.apply {
	normalCardElevation = 4
	pessedCardElevation = 10
	cardPressedColor = Color.parseColor("#e0e0e0")
	isAnimationEnabled = true
	clickDelay = 150
}

Java

CardViewPlus cardViewPlus = findViewById(R.id.cardViewPlus);
cardViewPlus.setNormalCardElevation(4);
cardViewPlus.setPressedCardElevation(10);
cardViewPlus.setCardPressedColor(Color.parseColor("#e0e0e0"));
cardViewPlus.setAnimationEnabled(true);
cardViewPlus.setClickDelay(150);


Support

Find this library useful? Support it by joining stargazers for this repository
And follow me for my next creations

License

CardViewPlus by Ali Bardide is licensed under a Apache License 2.0.