Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit f86f535

Browse files
committed
Replace doOnNextLayout with doOnLayout
1 parent 5a11938 commit f86f535

File tree

1 file changed

+6
-4
lines changed
  • Motion/app/src/main/java/com/example/android/motion/demo/oscillation

1 file changed

+6
-4
lines changed

Motion/app/src/main/java/com/example/android/motion/demo/oscillation/CheeseAdapter.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import android.view.ViewGroup
2121
import android.widget.EdgeEffect
2222
import android.widget.ImageView
2323
import android.widget.TextView
24+
import androidx.core.view.doOnLayout
2425
import androidx.core.view.doOnNextLayout
2526
import androidx.dynamicanimation.animation.SpringAnimation
2627
import androidx.dynamicanimation.animation.SpringForce
@@ -112,16 +113,17 @@ internal class CheeseAdapter : ListAdapter<Cheese, CheeseViewHolder>(Cheese.DIFF
112113
}
113114

114115
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CheeseViewHolder {
115-
return CheeseViewHolder(parent)
116+
return CheeseViewHolder(parent).apply {
117+
// The rotation pivot should be at the center of the top edge.
118+
itemView.doOnLayout { v -> v.pivotX = v.width / 2f }
119+
itemView.pivotY = 0f
120+
}
116121
}
117122

118123
override fun onBindViewHolder(holder: CheeseViewHolder, position: Int) {
119124
val cheese = getItem(position)
120125
Glide.with(holder.image).load(cheese.image).into(holder.image)
121126
holder.name.text = cheese.name
122-
// The rotation pivot should be at the center of the top edge.
123-
holder.itemView.doOnNextLayout { v -> v.pivotX = v.width / 2f }
124-
holder.itemView.pivotY = 0f
125127
}
126128
}
127129

0 commit comments

Comments
 (0)