我在中添加了AnimatorListenerAdapter一个ValueAnimator,但我需要ValueAnimator在它运行时停止。
我尝试过ValueAnimator.cancel()或ValueAnimator.stop(),它们都可以停止动画制作器,但是AnimatorListenerAdapter.onAnimationEnd()我不希望这样调用。
ValueAnimator.pause() 可以,但是只能在api 19以上,所以我不能使用它;
无论如何我还能做到吗?
我想要实现的应该是非常简单的,但它不起作用.我在我的地图上添加了一个标记,我正试图为它制作一个心跳动画.
我试过以下代码,但没有运气,
ObjectAnimator pulse = ObjectAnimator.ofPropertyValuesHolder(userLocation,
PropertyValuesHolder.ofFloat("scaleX",2f),
PropertyValuesHolder.ofFloat("scaleY",2f)
);
pulse.setDuration(310);
pulse.setRepeatCount(ObjectAnimator.INFINITE);
pulse.setRepeatMode(ObjectAnimator.REVERSE);
pulse.start();
Run Code Online (Sandbox Code Playgroud)
任何建议都会很感激,加上使用外部库也可以是一个选项,我刚刚找不到.
使用alpha作为propertyName的objectAnimator根本不做任何事.在objectAnimator被连接到一个path内部的vector.
fading_animator.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:duration="700"
android:propertyName="alpha"
android:valueFrom="1"
android:valueTo="0"
android:valueType="floatType"
android:repeatCount="infinite"
android:repeatMode="restart"/>
</set>
Run Code Online (Sandbox Code Playgroud)
animated_vector.xml:
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/vector_drawable">
<target
android:name="pathTarget"
android:animation="@animator/fading_animator"/>
</animated-vector>
Run Code Online (Sandbox Code Playgroud) 我试图做一个类似IPhone coverflow的动画师,但更简单一点.现在我试图进行旋转,然后使图像全屏,但什么也没发生.
ImageView i = (ImageView) FindViewById(args.Position);
var disp = WindowManager.DefaultDisplay;
var height = disp.Height;
var width = disp.Width;
ObjectAnimator anim = ObjectAnimator.OfInt(i, "rotationY", 0, 180);
ObjectAnimator scaleX = ObjectAnimator.OfInt(i, "scaleX", width);
ObjectAnimator scaleY = ObjectAnimator.OfInt(i, "scaleY", height);
AnimatorSet set = new AnimatorSet();
set.Play(anim).With(scaleX).With(scaleY);
Run Code Online (Sandbox Code Playgroud)
代码有什么问题?为什么没有发生?
当我单击开始按钮,然后结束按钮并再次单击开始按钮会导致以下异常:
10-08 08:57:57.963: E/AndroidRuntime(2009): java.lang.IllegalStateException: Circular dependencies cannot exist in AnimatorSet
10-08 08:57:57.963: E/AndroidRuntime(2009): at android.animation.AnimatorSet.sortNodes(AnimatorSet.java:848)
10-08 08:57:57.963: E/AndroidRuntime(2009): at android.animation.AnimatorSet.start(AnimatorSet.java:486)
10-08 08:57:57.963: E/AndroidRuntime(2009): at com.example.propertyanimation.IndividualPropertyAnimationActivity$1.onClick(IndividualPropertyAnimationActivity.java:51)
10-08 08:57:57.963: E/AndroidRuntime(2009): at android.view.View.performClick(View.java:4240)
Run Code Online (Sandbox Code Playgroud)
源代码:
pvhX = PropertyValuesHolder.ofFloat(View.SCALE_X, 2);
pvhY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 2);
scaleAnimation = ObjectAnimator.ofPropertyValuesHolder(mSubject, pvhX, pvhY);
scaleAnimation.setRepeatCount(0);
scaleAnimation.setRepeatMode(ValueAnimator.REVERSE);
scaleAnimation.setDuration(3000);
rotateAnimation = ObjectAnimator.ofFloat(mSubject, View.ROTATION, 360);
rotateAnimation.setRepeatCount(ValueAnimator.INFINITE);
rotateAnimation.setDuration(2000);
mButtonStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setAniation.play(scaleAnimation).before(rotateAnimation);
setAniation.start();
}
});
mButtonEnd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setAniation.end();
}
});
Run Code Online (Sandbox Code Playgroud) 我正在学习如何使用 ObjectAnimator 在 android 上为对象设置动画,但我没有看到它更新了我的 setter 方法。假设我有一个自定义视图,它在显示器上绘制一个简单的文本,并且有一个 objectAnimator 将操作的私有变量 (curnum):
public class TempView extends View {
private Float cur_num = new Float(0.0);
private float curnum = 0f;
public TempView(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public void setCurnum()
{
curnum++;
cur_num = new Float(curnum);
invalidate();
}
@Override
public void onDraw(Canvas canvas)
{
Paint paint = new Paint();
paint.setStrokeWidth(8);
paint.setTextSize(100);
canvas.drawText(cur_num.toString(), 150, 150, paint);
}
}
Run Code Online (Sandbox Code Playgroud)
现在在我的 Activity 类上,我有一个启动动画的操作栏项目:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item …Run Code Online (Sandbox Code Playgroud) 我正在学习Java和Android SDK.我想创建一个简单的应用程序,交换2个按钮,使左边的一个移动到右边的位置,vv用简单的动画.我已经尝试过ObjectAnimator,因为我已经读过它正在永久地移动视图对象.但它不是:-(对象停留在那里我的意思是左边的那个和vv但是它们的getLeft(),getTop()值是相同的,并且在下一个动画开始后,对象立即返回到起始位置.已经读过ObjectAnimator需要一些额外的功能才能正常工作但是在文档中没有例子:-(我试图添加setTranslationX函数但它没有用.有人能给我提供一些简单的例子,说明怎么做这个?
http://developer.android.com/guide/topics/graphics/prop-animation.html#object-animator
"您正在设置动画的对象属性必须以set()的形式具有setter函数(在camel情况下).因为ObjectAnimator在动画期间自动更新属性,所以它必须能够使用此setter方法访问该属性.例如,如果属性名称为foo,则需要使用setFoo()方法.如果此setter方法不存在,则有三个选项:如果您有权这样做,请将setter方法添加到类中.您有权更改的包装类,并让该包装器使用有效的setter方法接收该值并将其转发给原始对象.请改用ValueAnimator."
提前致谢.
我使用Animator XML为ImageView设置动画.ImageView应该增长(从0f到1f,Y比X快)并从90°旋转90°到0.我将这个XML文件用于动画:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="together">
<objectAnimator
android:duration="500"
android:propertyName="scaleY"
android:valueFrom="0f"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:valueTo="1f"
android:valueType="floatType" />
<objectAnimator
android:duration="1000"
android:propertyName="scaleX"
android:valueFrom="0f"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:valueTo="1f"
android:valueType="floatType" />
<objectAnimator
android:duration="1000"
android:transformPivotX="0dp"
android:transformPivotY="0dp"
android:interpolator="@android:anim/linear_interpolator"
android:propertyName="rotate"
android:valueFrom="90"
android:valueType="floatType"
android:valueTo="0" />
</set>
Run Code Online (Sandbox Code Playgroud)
当我使用Animator时
AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(this,
R.animator.login_bubble_animation);
set.setTarget(mContactBubble);
set.start();
Run Code Online (Sandbox Code Playgroud)
除旋转之外的所有内容都有效,因此ImageView会增长但不会旋转.我已经习惯了
RotateAnimation rotate = new RotateAnimation(90, 0, Animation.RELATIVE_TO_SELF,
0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(1000);
mContactBubble.startAnimation(rotate);
Run Code Online (Sandbox Code Playgroud)
哪个确实有效,但如果它在XML文件中,那将是一个优势.
我试图让AnimatedVectorDrawable同时淡出和翻译.我做了一个ObjectAnimator资源:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:propertyName="translationX"
android:duration="@+string/animtime"
android:valueFrom="0"
android:valueTo="150"
android:valueType="floatType"/>
<objectAnimator
android:propertyName="alpha"
android:duration="@+string/animtime"
android:valueFrom="255"
android:valueTo="0"
android:valueType="intType"/>
Run Code Online (Sandbox Code Playgroud)
然后有针对性一个VectorDrawable用ObjectAnimation:
<target
android:name="disgust"
android:animation="@anim/fadetransout" />
Run Code Online (Sandbox Code Playgroud)
它VectorDrawable是资源文件<group>中的一个VectorDrawable.
但是当我开始动画时,什么都没发生.我究竟做错了什么?
我在堆栈跟踪中发现了这个:
Method setTranslationX() with type float not found on target class class android.graphics.drawable.VectorDrawable$VGroup
Method setAlpha() with type int not found on target class class android.graphics.drawable.VectorDrawable$VGroup
Run Code Online (Sandbox Code Playgroud)
它与此有关吗?
如果这是不可能的,还有另一种方法可以让我VectorDrawable淡化和翻译吗?
谢谢.
android android-animation objectanimator android-vectordrawable
我正在使用AnimatorSet playSequentially方法,如下所示:
AnimatorSet set = new AnimatorSet();
ObjectAnimator in = ObjectAnimator.ofFloat(splash, "alpha", 0f, 1f);
in.setDuration(2500);
in.setInterpolator(new AccelerateInterpolator());
ObjectAnimator out = ObjectAnimator.ofFloat(splash, "alpha", 1f, 0f);
out.setDuration(2500);
out.setInterpolator(new AccelerateInterpolator());
set.playSequentially(in,out);
Run Code Online (Sandbox Code Playgroud)
我想在动画1和2之间添加延迟,如下所示:
set.playSequentially(in,1000,out);
Run Code Online (Sandbox Code Playgroud)
使用playSequentially方法可以在动画之间添加延迟吗?
谢谢.
animation android android-animation objectanimator animatorset
我正在为 Android 制作游戏,但在进行下一次更新时遇到了问题。游戏设置为从 API 19 开始工作。我正在使用 ObjectAnimator 类为教程中指向按钮的小弹跳箭头设置动画。没有什么花哨。
代码:
//Animate minestone clicker button arrow
b1_animator = ObjectAnimator.ofFloat(button_minestone_pointer,"translationX",0,-100);
b1_animator.setDuration(500);
b1_animator.setRepeatMode(ValueAnimator.REVERSE);
b1_animator.setRepeatCount(Animation.INFINITE);
b1_animator.start();
Run Code Online (Sandbox Code Playgroud)
问题是,动画在 Android Studio (API 19 - API 27) 和所有更新的 API 提供的所有虚拟设备上都很流畅,但在我的手机 (Sharp SH-01G) 上,它运行的是 Android 4.4、自动滚动或这些箭头从一个位置跳转到另一个创建模糊图像。还没有机会在另一个 API21 之前的设备上检查它。感觉它不尊重“.setDuration();” 少量。卷轴会立即跳到所需的位置,但一点也不流畅。
这是滚动条代码:
ObjectAnimator.ofInt(scroller_clickers, "scrollX", 800).setDuration(777).start();
Run Code Online (Sandbox Code Playgroud)
所以问题是,是什么导致了这种行为?我也尝试使用 view.animate() 代替,但它也没有帮助。线索是,当我尝试查找“getAnimatedFraction();”时 值,模拟器显示各种分数 - 0.0 和 1 之间的平滑过渡。我的手机总是以某种随机顺序显示 0.0 或 1.0(将其填充到 TextView 中并使用 Runnable 刷新)。分配“AccelerateDecelerateInterpolator()”也不起作用。我不想向公众展示一个有缺陷的游戏:(
有任何想法吗?
android ×11
objectanimator ×11
java ×3
animation ×2
alpha ×1
animatorset ×1
google-maps ×1
imageview ×1
marker ×1
vector ×1
xamarin ×1
xml ×1