這兩種影片方法有什么區別?它們都達到了相同的結果,但第一個是生澀的,而第二個是平滑的。為什么?
這個影片進展順利,直到它突然跳到最終位置的最后。一切似乎都很簡單,這是怎么回事?
val cube = homeBinding.imgCube
val animSet = AnimationSet(true)
val rotateAnimation = RotateAnimation(0.0f,
720.0f,
Animation.RELATIVE_TO_SELF,
0.5f,
Animation.RELATIVE_TO_SELF,
0.5f)
val scaleAnimation: Animation = ScaleAnimation(
0.1f, 0.4f,
0.2f, 0.4f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f)
scaleAnimation.interpolator = LinearInterpolator()
rotateAnimation.interpolator = LinearInterpolator()
animSet.duration = 3000
animSet.addAnimation(rotateAnimation)
animSet.addAnimation(scaleAnimation)
cube.startAnimation(animSet)
和 xml:
<ImageView
android:id="@ id/imgCube"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:contentDescription="some"
android:scaleType="centerInside"
android:scaleX="0.4"
android:scaleY="0.4"
app:srcCompat="@drawable/kk" />

雖然這個作業得很好。
但有什么區別呢?
cube.animate().scaleX(0.4f)
.scaleY(0.4f)
.setDuration(3000)
.rotation(720f)
.setInterpolator (LinearInterpolator())
.start();

uj5u.com熱心網友回復:
第一種方法是使用RotateAnimation和ScaleAnimation與AnimationSet,第二種方法(對于這個任務來說更好,更不用說更短的代碼)是使用ViewPropertyAnimator。
我只能說我之前在 AnimationSet 和這些型別的影片中遇到了問題,所以我強烈推薦 ViewPropertyAnimator 來做進一步的影片
我猜在第一種方法中它會跳回來,因為您沒有在 AnimationSet 中指定 setFillAfter(true)方法,和/或它與 Pivots (RELATIVE_TO_SELF) 有關
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/353876.html
