當前位置: 首頁>>代碼示例>>Java>>正文


Java InertialImitator類代碼示例

本文整理匯總了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;
}
 
開發者ID:tumblr,項目名稱:Backboard,代碼行數:45,代碼來源:ConstrainedFragment.java


注:本文中的com.tumblr.backboard.imitator.InertialImitator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。