# ElasticViews
**Repository Path**: deviche/ElasticViews
## Basic Information
- **Project Name**: ElasticViews
- **Description**: :dizzy: A library that let you implement elastic touch animation.
- **Primary Language**: Kotlin
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2018-11-13
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# ElasticViews

[](https://travis-ci.org/skydoves/ElasticViews)
A library that let you implement elastic touch animation.


## Including in your project
#### build.gradle
```java
repositories {
mavenCentral() // or jcenter() works as well
}
dependencies {
implementation 'com.github.skydoves:elasticviews:2.0.1'
}
```
## Usage
ElasticViews let we use like using normal views and give all of the Views or GroupViews touch effect very simply.
#### Add XML Namespace
First add below XML Namespace inside your XML layout file.
```xml
xmlns:app="http://schemas.android.com/apk/res-auto"
```
#### OnClick Method
All of ElasticViews should be set OnClickListener or OnClick Method, etc. If not, nothing happens.
```java
ElasticButton elasticButton = (ElasticButton)findViewById(R.id.elasticbutton);
elasticButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// do something
}
});
```
or use butterknife
```java
@OnClick(R.id.elasticbutton)
public void onClick(View v){
// do something
}
```
### ElasticButton
```xml
```
### ElasticButton use like TextView
If _button_backgroundColor_ attribute set as _@android:color/transparent_
you can use ElasticButton looks like TextView.
```xml
app:button_backgroundColor="@android:color/transparent"
```
### ElasticCheckButton
```xml
```
### ElasticImageView
```xml
```
### ElasticFloatingButton
```xml
```
### ElasticLayout
ElasticLayout don't animation for child views.
If you want give ViewGroup animation, then use ElasticAnimation.
```xml
```
### ElasticAnmimation
ElasticAnimation lets we can implement elastic animation on all of the views.
```java
new ElasticAnimation(clickedView).setScaleX(0.9f).setScaleY(0.9f).setDuration(400)
.setOnFinishListener(onFinishListener).doAction();
```
or we can set ViewPropertyAnimatorListener using setListener method and detect animation start and end.
```java
.setListener(new ViewPropertyAnimatorListener() {
@Override
public void onAnimationStart(View view) {
}
@Override
public void onAnimationEnd(View view) {
finishListener.onFinished();
}
@Override
public void onAnimationCancel(View view) {
}
});
```
#### Kotlin Extension
ElasticAnimation supports kotlin extension __elasticAnimation__.
```kotlin
val anim = textView.elasticAnimation(0.8f, 0.8f, 400, object: ElasticFinishListener {
override fun onFinished() {
// do anything
}
})
anim.doAction()
```
#### Example : Normal Button
we can implement animation on all of the views like below.
```java
@OnClick(R.id.button)
public void addNewAlarm(View v){
// implements animation uising ElasticAnimation
new ElasticAnimation(v).setScaleX(0.85f).setScaleY(0.85f).setDuration(500)
.setOnFinishListener(new ElasticFinishListener() {
@Override
public void onFinished() {
// Do something after duration time
}
}).doAction();
}
}
```
#### Example : ListView Item
So also we can implement animation on listView's items like below.
```java
private class ListViewItemClickListener implements AdapterView.OnItemClickListener{
@Override
public void onItemClick(AdapterView> adapterView, View clickedView, final int pos, long id) {
new ElasticAnimation(clickedView).setScaleX(0.9f).setScaleY(0.9f).setDuration(400)
.setOnFinishListener(new ElasticFinishListener() {
@Override
public void onFinished() {
//Do something after duration time
Toast.makeText(getBaseContext(), "ListViewItem" + pos, Toast.LENGTH_SHORT).show();
}
}).doAction();
}
};
```
#### ElasticAnimation Preview

# License
```xml
The MIT License (MIT)
Copyright (c) 2017 skydoves
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
```