我尝试使用android android.animation.ObjectAnimator 在圆形路径中移动视图对象
我尝试使用此方法,但收到错误消息路径必须从(0,0)开始,并在(1,1)结束
这是特定视图对象的OnClick()方法
public void onPathAnimation(View view){
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
Path path = new Path();
path.moveTo(view.getX(), view.getY()+100);
path.addCircle(view.getX(), view.getY(), 100, Path.Direction.CW);
PathInterpolator pathInterpolator = new PathInterpolator(path);
ObjectAnimator animator = ObjectAnimator.ofFloat(view, "translationX", 100f);
animator.setInterpolator(pathInterpolator);
// animator.setDuration(2000);
animator.start();
}
}
这是我得到的例外
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5265)
at android.view.View$PerformClick.run(View.java:21534)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5737)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5265)
at android.view.View$PerformClick.run(View.java:21534)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5737)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Caused by: java.lang.IllegalArgumentException: The Path must start at (0,0) and end at (1,1)
at android.view.animation.PathInterpolator.initPath(PathInterpolator.java:164)
at android.view.animation.PathInterpolator.<init>(PathInterpolator.java:61)
at com.kalana.materialtest.MainActivity.onPathAnimation(MainActivity.java:179)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5265)
at android.view.View$PerformClick.run(View.java:21534)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5737)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
感谢你的建议。
2条答案
按热度按时间ffscu2ro1#
试试这个:
8ulbf1ek2#
我使用的是
addOval
方法,不需要定义任何Angular 。