@@ -8,6 +8,8 @@ import android.widget.ImageView
88import android.widget.LinearLayout
99import androidx.appcompat.app.AppCompatActivity
1010import androidx.appcompat.widget.Toolbar
11+ import androidx.core.view.forEach
12+ import androidx.core.view.forEachIndexed
1113import com.jawnnypoo.physicslayout.Physics
1214import com.jawnnypoo.physicslayout.PhysicsConfig
1315import com.jawnnypoo.physicslayout.Shape
@@ -43,9 +45,11 @@ class MainActivity : AppCompatActivity() {
4345 binding.physicsSwitch.setOnCheckedChangeListener { _, isChecked ->
4446 binding.physicsLayout.physics.isPhysicsEnabled = isChecked
4547 if (! isChecked) {
46- for (i in 0 until binding.physicsLayout.childCount) {
47- binding.physicsLayout.getChildAt(i)
48- .animate().translationY(0f ).translationX(0f ).rotation(0f )
48+ binding.physicsLayout.forEach {
49+ it.animate()
50+ .translationY(0f )
51+ .translationX(0f )
52+ .rotation(0f )
4953 }
5054 }
5155 }
@@ -71,10 +75,9 @@ class MainActivity : AppCompatActivity() {
7175 }
7276
7377
74- for (i in 0 until binding.physicsLayout.childCount) {
75- val imageView = binding.physicsLayout.getChildAt(i) as ImageView
76- imageView.id = i
77- imageView.setImageResource(R .drawable.ic_logo)
78+ binding.physicsLayout.forEachIndexed { index, view ->
79+ view.id = index
80+ (view as ImageView ).setImageResource(R .drawable.ic_logo)
7881 }
7982 index = binding.physicsLayout.childCount + 1
8083
0 commit comments