Skip to content

Commit 78c9840

Browse files
Update README.md
1 parent 1a7be6e commit 78c9840

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ fragment transitions, image to ViewPager transitions and more.
2121
| ----------|----------------| --------|
2222
| <img src="./screenshots/chapter2_7gradient.gif"/> | <img src="./screenshots/chapter2_8counter_textview.gif"/> | <img src="./screenshots/chapter2_9_counter_surfaceview.gif"/> |
2323

24-
| Ch3-1 Physics | Ch3-2 Scale and Chained | Ch3-3 Fling | Ch3-4 BNV+TabLayout Physics|
25-
| ----------|----------------| --------| --------|
26-
| <img src="./screenshots/chapter3_1physics_basics.gif"/> | <img src="./screenshots/chapter3_2scale_and_chain.gif"/> | <img src="./screenshots/chapter3_fling_animation.gif"/> | <img src="./screenshots/chapter3_4_bnv_tablayout_animation.gif"/> |
24+
| Ch3-1 Physics | Ch3-2 Scale and Chained | Ch3-3 Fling | Ch3-4 BNV+TabLayout Physics| Ch3-4 BNV+TabLayout Physics|
25+
| ----------|----------------| --------| --------| --------|
26+
| <img src="./screenshots/chapter3_1physics_basics.gif"/> | <img src="./screenshots/chapter3_2scale_and_chain.gif"/> | <img src="./screenshots/chapter3_3fling_animation.gif"/> | <img src="./screenshots/chapter3_4bnv_tablayout_animation.gif"/> | <img src="./screenshots/chapter3_5elastic_scale.gif"/> |
2727

2828
<br>
2929

Tutorial1-1Basics/src/main/java/com/example/tutorial1_1basics/chapter3_physics/Activity3_5ElasticScale.kt

+20-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import android.view.ViewPropertyAnimator
1010
import android.view.animation.AccelerateDecelerateInterpolator
1111
import android.view.animation.Interpolator
1212
import android.widget.Button
13+
import android.widget.Toast
1314
import androidx.appcompat.app.AppCompatActivity
1415
import androidx.dynamicanimation.animation.DynamicAnimation
1516
import androidx.dynamicanimation.animation.SpringAnimation
@@ -133,6 +134,21 @@ class Activity3_5ElasticScale : AppCompatActivity() {
133134

134135
fab.setElasticTouchListener(duration = 300)
135136

137+
fab.setOnClickListener {
138+
Toast.makeText(applicationContext, "TOAST", Toast.LENGTH_SHORT).show()
139+
}
140+
141+
}
142+
}
143+
144+
fun View.setElasticOnClickListener(
145+
grow: Boolean = false,
146+
scaleBy: Float = 0.1f,
147+
duration: Long = 200,
148+
interpolator: Interpolator = LinearOutSlowInInterpolator()
149+
) {
150+
setOnClickListener {
151+
elasticAnimation(grow, scaleBy, duration, interpolator)
136152
}
137153
}
138154

@@ -175,12 +191,12 @@ fun View.elasticAnimation(
175191
scaleY = initialScaleY
176192
viewPropertyAnimator.setListener(null)
177193
}
178-
179194
})
180195
}
181196

182197
@SuppressLint("ClickableViewAccessibility")
183198
fun View.setElasticTouchListener(
199+
onTouchStart: (() -> Unit)? = null,
184200
grow: Boolean = false,
185201
scaleBy: Float = 0.1f,
186202
duration: Long = 200,
@@ -209,6 +225,8 @@ fun View.setElasticTouchListener(
209225

210226
MotionEvent.ACTION_DOWN -> {
211227

228+
onTouchStart?.invoke()
229+
212230
startPropertyAnimator = animate()
213231

214232
startPropertyAnimator
@@ -247,7 +265,6 @@ fun View.setElasticTouchListener(
247265
})
248266
}
249267
}
250-
251-
true
268+
false
252269
}
253270
}
641 KB
Loading
Loading
402 KB
Loading

0 commit comments

Comments
 (0)