本文整理汇总了Java中com.tumblr.backboard.imitator.InertialImitator类的典型用法代码示例。如果您正苦于以下问题:Java InertialImitator类的具体用法?Java InertialImitator怎么用?Java InertialImitator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InertialImitator类属于com.tumblr.backboard.imitator包,在下文中一共展示了InertialImitator类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateView
import com.tumblr.backboard.imitator.InertialImitator; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_constrain, container, false);
final View constraintView = rootView.findViewById(R.id.constraint);
final View circle = rootView.findViewById(R.id.circle);
final InertialImitator motionImitatorX =
new InertialImitator(MotionProperty.X, Imitator.TRACK_DELTA,
Imitator.FOLLOW_SPRING, 0, 0);
final InertialImitator motionImitatorY =
new InertialImitator(MotionProperty.Y, Imitator.TRACK_DELTA,
Imitator.FOLLOW_SPRING, 0, 0);
new Actor.Builder(SpringSystem.create(), circle)
.addMotion(motionImitatorX, View.TRANSLATION_X)
.addMotion(motionImitatorY, View.TRANSLATION_Y)
.build();
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
motionImitatorX.setMinValue(
-constraintView.getMeasuredWidth() / 2 + circle.getMeasuredWidth() / 2);
motionImitatorX.setMaxValue(
constraintView.getMeasuredWidth() / 2 - circle.getMeasuredWidth() / 2);
motionImitatorY.setMinValue(
-constraintView.getMeasuredHeight() / 2 + circle.getMeasuredWidth() / 2);
motionImitatorY.setMaxValue(
constraintView.getMeasuredHeight() / 2 - circle.getMeasuredWidth() / 2);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
rootView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
});
return rootView;
}