【发布时间】:2021-08-28 02:15:55
【问题描述】:
我正在开发一个相机应用程序,我想要双击来缩放。我能够实现这一点,但后来我想通过动画缩放来改进应用程序的用户体验。我尝试应用 Ticker 逻辑来做到这一点,但从 CameraX API 执行简单的缩放调用需要自己的时间(高到无法在流畅的动画中使用它。有什么方法可以从当前动画缩放将值缩放到期望值?
代码:
public boolean onDoubleTap(MotionEvent e) {
Log.i(TAG, "===============Double tap detected.=========");
final ZoomState zoomState = camera.getCameraInfo().getZoomState().getValue();
float start, diff;
if(zoomState!=null) {
start = zoomState.getZoomRatio();
diff = start * 0.5f;
final Calendar calendar = Calendar.getInstance();
final int ANIM_DURATION_IN_MS = 2000;
final long endTime = Calendar.getInstance().getTimeInMillis() + ANIM_DURATION_IN_MS;
double elapsed = 1.0;
while(elapsed>0.0) {
elapsed = endTime - Calendar.getInstance().getTimeInMillis();
double d = 1 - elapsed/(float)ANIM_DURATION_IN_MS;
Log.i(TAG, "getTime: " + Calendar.getInstance().getTimeInMillis());
Log.i(TAG, "endTime: " + endTime);
Log.i(TAG, "d: " + d);
try {
camera.getCameraControl().setZoomRatio((float) (start+(diff*d))).get();
} catch (ExecutionException | InterruptedException executionException) {
executionException.printStackTrace();
}
Log.i(TAG, "zoomRatio: " + (float) (start+diff*d));
}
Log.i(TAG, "Done");
camera.getCameraControl().setZoomRatio(start+diff);
}
return super.onDoubleTap(e);
}
【问题讨论】:
标签: java android android-camerax