? ?最近遇到很奇怪的问题。发现View.animate().scaleX()失效的。
? 如代码如下:
? ?
frameworks/base/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java
public void stopDrag() {
itemView.animate()
.setDuration(DRAG_LENGTH)
.scaleX(1)
.scaleY(1);
mTileView.findViewById(R.id.tile_label).animate()
.setDuration(DRAG_LENGTH)
.alpha(1);
mTileView.getAppLabel().animate()
.setDuration(DRAG_LENGTH)
.alpha(.6f);
}
? ? 发现在调用 itemView.animate().setDuration(DRAG_LENGTH).scaleX(1).scaleY(1); 不起作用。导致的问题是?:当之前调用itemView.animate() 的行为无法恢复。
如 所报的bug :
[SystemUI][100%]前提:语言为西班牙语。下拉状态栏,点击编辑,长按storage或者Focus mode时,字体重叠(具体见视频)。
步骤:前提:语言为西班牙语
1、下拉状态栏,点击编辑,长按storage或者Focus mode
问题点:字体重叠 期望结果:字体不会重叠
分析:
针对此问题,尝试添加log,进行跟踪.
itemView.animate()
.setDuration(DRAG_LENGTH)
.scaleX(1)
.scaleY(1).setListener(new Animator.AnimatorListener(){
public void onAnimationStart(Animator animation){
Log.e("XIBIN", "TileAdapter ::stopDrag onAnimationStart");
}
public void onAnimationEnd(Animator animation){
Log.e("XIBIN", "TileAdapter ::stopDrag onAnimationEnd",new RuntimeException());
}
public void onAnimationCancel(Animator animation){
Log.e("XIBIN", "TileAdapter ::stopDrag onAnimationCancel",new RuntimeException());
}
public void onAnimationRepeat(Animator animation){
Log.e("XIBIN", "TileAdapter ::stopDrag onAnimationRepeat");
}
});
通过打印log ,发现有 onAnimationCancel 字样的关键字输出,并存在打印堆栈
08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : TileAdapter ::stopDrag onAnimationCancel 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : java.lang.RuntimeException 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at com.android.systemui.qs.customize.TileAdapter$Holder$1.onAnimationCancel(TileAdapter.java:520) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.ViewPropertyAnimator$AnimatorEventListener.onAnimationCancel(ViewPropertyAnimator.java:1086) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.animation.ValueAnimator.cancel(ValueAnimator.java:1132) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.ViewPropertyAnimator.cancel(ViewPropertyAnimator.java:424) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at androidx.recyclerview.widget.DefaultItemAnimator.endAnimation(DefaultItemAnimator.java:439) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at androidx.recyclerview.widget.DefaultItemAnimator.resetAnimation(DefaultItemAnimator.java:526) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at androidx.recyclerview.widget.DefaultItemAnimator.animateMove(DefaultItemAnimator.java:260) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at androidx.recyclerview.widget.SimpleItemAnimator.animatePersistence(SimpleItemAnimator.java:138) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at androidx.recyclerview.widget.RecyclerView$4.processPersistent(RecyclerView.java:643) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at androidx.recyclerview.widget.ViewInfoStore.process(ViewInfoStore.java:239) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep3(RecyclerView.java:4299) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3952) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4499) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.View.layout(View.java:23005) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.ViewGroup.layout(ViewGroup.java:6453) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.widget.LinearLayout.onLayout(LinearLayout.java:1582) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.View.layout(View.java:23005) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.ViewGroup.layout(ViewGroup.java:6453) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.widget.LinearLayout.onLayout(LinearLayout.java:1582) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.View.layout(View.java:23005) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.ViewGroup.layout(ViewGroup.java:6453) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.widget.FrameLayout.onLayout(FrameLayout.java:270) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at com.android.systemui.qs.QSContainerImpl.onLayout(QSContainerImpl.java:193) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.View.layout(View.java:23005) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.ViewGroup.layout(ViewGroup.java:6453) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.widget.FrameLayout.onLayout(FrameLayout.java:270) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.View.layout(View.java:23005) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.ViewGroup.layout(ViewGroup.java:6453) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.widget.FrameLayout.onLayout(FrameLayout.java:270) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.View.layout(View.java:23005) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.ViewGroup.layout(ViewGroup.java:6453) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.widget.FrameLayout.onLayout(FrameLayout.java:270) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.View.layout(View.java:23005) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.ViewGroup.layout(ViewGroup.java:6453) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.widget.FrameLayout.onLayout(FrameLayout.java:270) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.View.layout(View.java:23005) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.ViewGroup.layout(ViewGroup.java:6453) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3580) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3038) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2020) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8410) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.Choreographer$CallbackRecord.run(Choreographer.java:974) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.Choreographer.doCallbacks(Choreographer.java:797) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.Choreographer.doFrame(Choreographer.java:732) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:959) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.os.Handler.handleCallback(Handler.java:938) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.os.Handler.dispatchMessage(Handler.java:99) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.os.Looper.loop(Looper.java:230) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at android.app.ActivityThread.main(ActivityThread.java:7700) 08-11 17:03:51.874 ?1175 ?1175 E XIBIN ? : ?? ?at java.lang.reflect.Method.invoke(Native Method) 08-11 17:03:51.875 ?1175 ?1175 E XIBIN ? : ?? ?at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612) 08-11 17:03:51.875 ?1175 ?1175 E XIBIN ? : ?? ?at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:997)
发现在执行?onLayout() ,排列布局时,将动画cancel了。 知道此原因之后,可以延后执行,使用postDelayed 延后100毫秒。测试正常。
总结:
? ? ? ?遇到类似的问题,多查看源码并在关键之后添加log进行分析。
|