本文整理匯總了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;
}