- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
当我在我的自定义 View 中运行此代码时,onAnimationStart
和 onAnimationEnd
一直被重复调用。这不是很奇怪吗?作为一名 Android 程序员,我希望它们分别只被调用一次。
final ViewPropertyAnimator animator = animate().setDuration(1000).alpha(0.0f);
animator.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
Utils.log("----------------start");
}
@Override
public void onAnimationEnd(Animator animation) {
Utils.log("--------- end");
}
}).start();
但是当 ViewPropertyAnimator
的 setListener(null)
调用 onAnimationEnd
时,我试图通过移除监听器来解决这个问题。但不管文档中写了什么,它都没有用:
public ViewPropertyAnimator setListener (Animator.AnimatorListener listener)
Added in API level 12
Sets a listener for events in the underlying Animators that run the property animations.
Parameters
listener The listener to be called with AnimatorListener events. A value of null removes any existing listener.
Returns
This object, allowing calls to methods in this class to be chained.
有没有其他人遇到过这个奇怪的问题?也许这是 Android 的错误?
最佳答案
我刚遇到这个问题,但没有自定义 View 。
在我的例子中,我在同一个 View 上有两个动画。一个显示和隐藏。
原来如此
showView(){
myView.animate().translationY(myView.getHeight()).setListener(new ...{
...
onAnimationEnd(Animation animation){
hideView();
}
...}).start();
}
hideView(){
myView.animate().translationY(0).start();
}
当 hideView() 完成时,它会再次调用自己。这是因为旧的监听器仍然存在。修复它的关键最终是在第二个动画中将监听器设置为 null。例如
hideView(){
myView.animate().translationY(0).setListener(null).start();
}
关于android - 无法删除 ViewPropertyAnimator 的监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29407214/
我目前正在使用 ViewPropertyAnimators 来缩放 ImageView。然而,问题是图像总是从中心向外缩放,当我希望它从最左边缩放并向右缩放时。似乎没有枢轴方法。我还有其他方法可以做到
每次按下按钮时,我都尝试使用 ViewPropertyAnimator 来缩放 View (不确定的 ProgressBar)。 loadingCircle.animate().scaleY(1.5f
我将以下代码用于 AppBarLayout 的滑入/滑出切换。 public void showToolbar(boolean show) { if (appBar == null) {
使用 Animator 类,您可以简单地调用如下代码来同时播放多个动画: AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTo
我在我的布局中设置了两个 ImageView(s),一个在另一个之上,比如 A 和 B。 我已将 B 的 alpha 设置为 0,因此它完全褪色,因为我想通过在我的代码中将适当的 alpha 设置为
我正在尝试使用 ViewPropertyAnimator 淡入具有可变持续时间的 ImageView,但我无法让它工作。 这是我用于淡出的代码,效果很好: final ImageView imageV
ViewPropertyAnimator(交叉淡入淡出效果)和 TransitionDrawable 之间的主要区别是什么?虽然两者似乎都在图像过渡上实现了相同的交叉淡入淡出效果。 最佳答案 Tran
使用 ObjectAnimator,可选地使用 PropertyValuesHolder,可以指定动画属性的起始值和结束值: ObjectAnimator animX = ObjectAnimator
当我在我的自定义 View 中运行此代码时,onAnimationStart 和 onAnimationEnd 一直被重复调用。这不是很奇怪吗?作为一名 Android 程序员,我希望它们分别只被调用
我想构建 TextViews 的动画,它在完成后立即重复。 对于我想要动画的每个 View ,我使用下面的代码 final float oldX = v.getX(); final float new
有没有办法在使用 ViewPropertyAnimator 时指定重复计数/模式? 最佳答案 不幸的是,ViewPropertyAnimator 没有任何方法来指定它执行的动画的重复次数。正如 Vie
ObjectAnimator 和 ViewPropertyAnimator 改变属性值有什么区别? ObjectAnimator objectAnimator = ObjectAnimator.ofF
如何使用 ViewPropertyAnimator 设置 View 宽度? 我可以缩放或平移(见下文)但我无法设置为特定宽度。 frame_1.animate().scaleX(5).scaleY(5
有时我会看到这样的代码 view.animate().alpha(1).start(); 有时 view.animate().alpha(1); 有什么区别(如果有的话)? 动画总是开始,但根据我对源
我是安卓动画的初学者。我在 RelativeLayout 中几乎没有 View ,我希望更改 View 位置。我有哪些选择,它们有何不同? 我试过以下方法: view.animate() .trans
我正在像这样使用 ViewPropertyAnimator: view.animate().alpha(to).setDuration(duration); 和 ValueAnimator: Valu
ViewPropertyAnimators (http://developer.android.com/reference/android/view/ViewPropertyAnimator.html
我试图在使用 ViewPropertyAnimator 将图像加载到属于 RecyclerView 内另一个 View 的 View 中后淡入图像。查看调试输出一切看起来都很好,但图像仍然不可见。 如
我正在尝试在 Android (API 15) 中为一个 View 设置动画,因此它通过从顶部向下扩展来显示,并通过向后收缩来隐藏,就像 this jQuery slideUp()/slideDown
我在 android 中使用如下所述的 View 属性动画器。它在大多数设备上运行良好,但在某些设备上会出现上述错误。它也总是在模拟器中失败。对象动画师也有同样的问题。请注意,如果应用在单个 View
我是一名优秀的程序员,十分优秀!