编程动画Android BrokenView



我正在浏览一些很棒的Android库,我发现了Android BrokenView。它使用起来非常简单,并使用触摸事件来显示破碎的动画。以下是我们需要添加的代码,以便使View表现为BrokenView:

brokenView = BrokenView.add2Window(context);
listener = new BrokenTouchListener.Builder(brokenView).build();
view.setOnTouchListener(listener);

我的问题是,我想执行破碎的动画编程,即没有任何实际的触摸事件。我试着看源代码,但无法弄清楚如何实现,因为大多数方法都是protected

我该怎么做呢?

我已经使用一个运动事件实现了这一点。它可以工作,但我更喜欢直接调用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

最新更新