Skip to content

Instantly share code, notes, and snippets.

package com.android.animationproject.view
import android.animation.AnimatorSet
import android.os.Bundle
import android.view.View
import android.view.ViewTreeObserver.OnGlobalLayoutListener
import androidx.appcompat.app.AppCompatActivity
import androidx.cardview.widget.CardView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
private fun collapseAnimation() {
val changeColor = AnimatorUtils.changeColor(
cardBox::setCardBackgroundColor,
ContextCompat.getColor(this, R.color.white),
ContextCompat.getColor(this, R.color.red),
500)
val resize = AnimatorUtils.resize(cardBox, newHeight, oldHeight, 250)
val fadeOut = AnimatorUtils.hideWithFadeOut(detail, 200)
val fadeIn = AnimatorUtils.showWithFadeIn(intro, 300)
private fun expandAnimation() {
val changeColor = AnimatorUtils.changeColor(
cardBox::setCardBackgroundColor,
ContextCompat.getColor(this, R.color.red),
ContextCompat.getColor(this,R.color.white),
500)
val resize = AnimatorUtils.resize(cardBox, oldHeight, newHeight, 300)
val fadeOut = AnimatorUtils.hideWithFadeOut(intro, 200)
val fadeIn = AnimatorUtils.showWithFadeIn(detail, 300)
private fun setViewHeight() {
intro.viewTreeObserver.addOnGlobalLayoutListener(
object : OnGlobalLayoutListener {
override fun onGlobalLayout() {
oldHeight = intro.getHeight()
intro.viewTreeObserver.removeOnGlobalLayoutListener(this)
}
})
detail.viewTreeObserver.addOnGlobalLayoutListener(
package com.android.animationproject.utils
import android.animation.*
import android.view.View
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
object AnimatorUtils {
fun changeColor(
backgroundColor: (Int) -> Unit,
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".view.ExpandViewActivity"
@AmaroNeto
AmaroNeto / layout_2.xml
Last active February 26, 2020 17:10
layout view expanded
<?xml version="1.0" encoding="utf-8"?>
<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:background="?attr/selectableItemBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
@AmaroNeto
AmaroNeto / layout_1.xml
Last active February 26, 2020 17:10
view layout collapsed
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
tools:background="@color/red">
@AmaroNeto
AmaroNeto / AdapterObject-9.kt
Created January 23, 2020 20:00
AdapterObject-9
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String): Boolean {
adapter?.filter?.filter(query)
return false
}
override fun onQueryTextChange(query: String): Boolean {
adapter?.filter?.filter(query)
return false
}
})
@AmaroNeto
AmaroNeto / AdapterObject-8.kt
Created January 23, 2020 19:59
AdapterObject-8
adapter = GenericAdapter<Movie>(movies)
adapter?.listener = this
recyclerView.adapter = adapter