我已经使用运动事件实现了这一点。它可以工作,但我更愿意直接调用createAnimator(),因为我不希望用户能够通过触摸事件触发粉碎。
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis()+1000;
int[] coords = new int[2];
targetView.getLocationOnScreen(coords);
float x = coords[0] + targetView.getWidth()/2;
float y = coords[1] + targetView.getHeight()/2;
MotionEvent motionEvent = MotionEvent.obtain(
downTime,
eventTime,
MotionEvent.ACTION_DOWN,
x,
y,
0
);
mBrokenTouchListener = new BrokenTouchListener.Builder(mBrokenView)
.setEnableArea(mRootView)
.build();
mBrokenTouchListener.onTouch(targetView, motionEvent);
我想要做的是这样的:
Point point = new Point((int)x, (int)y);
BrokenConfig config = new BrokenConfig();
brokenView.createAnimator(mFLTargetView, point, config);
brokenView.setEnable(true);
// or
brokenView.start();
但BrokenConfig是包私有的,而且也没有start()方法。
HTH
它是在[onTouch()](https://github.com/zhanyongsheng/BrokenView/blob/master/brokenview/src/main/java/com/zys/brokenview/BrokenTouchListener.java )。自己复制并编辑它 –
是的,我看到了,但我想以编程方式启动动画('brokenAnim.start();'),而不是触摸事件 –