我已經使用運動事件實現了這一點。它可以工作,但我更願意直接調用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();'),而不是觸摸事件 –