public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Use this to return your custom view for this Fragment // return inflater.Inflate(Resource.Layout.YourFragment, container, false); //return base.OnCreateView(inflater, container, savedInstanceState); View rootView = inflater.Inflate(Resource.Layout.origami_example, container, false); mPhotoGrid = rootView.FindViewById <View>(Resource.Id.grid); mSelectedPhoto = rootView.FindViewById <View>(Resource.Id.selection); mFeedbackBar = rootView.FindViewById <View>(Resource.Id.feedback); SpringSystem springSystem = SpringSystem.Create(); mSpring = springSystem.CreateSpring().SetSpringConfig(ORIGAMI_SPRING_CONFIG); mSpring.AddListener(new MapPerformer(mSelectedPhoto, View.ScaleXs, 0f, 1f, 0.33f, 1)); mSpring.AddListener(new MapPerformer(mSelectedPhoto, View.ScaleYs, 0f, 1f, 0.33f, 1)); mSpring.AddListener(new MapPerformer(mSelectedPhoto, ViewHelper.TranslationX, 0, 1, Util.DpToPx(-106.667f, Resources), 0)); mSpring.AddListener(new MapPerformer(mSelectedPhoto, ViewHelper.TranslationY, 0, 1, Util.DpToPx(46.667f, Resources), 0)); mSpring.AddListener(new MapPerformer(mPhotoGrid, ViewHelper.Alpha, 0, 1, 1, 0)); mSpring.AddListener(new MapPerformer(mPhotoGrid, View.ScaleXs, 0f, 1f, 1f, 0.95f)); mSpring.AddListener(new MapPerformer(mPhotoGrid, View.ScaleYs, 0f, 1f, 1f, 0.95f)); EventHandler globalHandler = null; globalHandler += (sender, e) => { float barPosition = (float)SpringUtil.MapValueFromRangeToRange(mSpring.CurrentValue, 0, 1, mFeedbackBar.Height, 0); mFeedbackBar.TranslationY = barPosition; mSpring.AddListener(new MapPerformer(mFeedbackBar, ViewHelper.TranslationY, 0, 1, mFeedbackBar.Height, 0)); rootView.ViewTreeObserver.GlobalLayout -= globalHandler; }; rootView.ViewTreeObserver.GlobalLayout += globalHandler; ToggleImitator imitator = new ToggleImitator(mSpring, 0, 1); rootView.SetOnTouchListener(imitator); mSpring.SetCurrentValue(0); return(rootView); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRootView = (RelativeLayout)inflater.Inflate(Resource.Layout.fragment_flower, container, false); mCircles = new View[6]; mCircle = mRootView.FindViewById(Resource.Id.circle); float diameter = TypedValue.ApplyDimension(ComplexUnitType.Dip, DIAMETER, Resources.DisplayMetrics); TypedArray circles = Resources.ObtainTypedArray(Resource.Array.circles); // layout params RelativeLayout.LayoutParams paramss = new RelativeLayout.LayoutParams((int)diameter, (int)diameter); paramss.AddRule(LayoutRules.CenterInParent); // create the circle views int colorIndex = 0; for (int i = 0; i < mCircles.Length; i++) { mCircles[i] = new View(Activity); mCircles[i].LayoutParameters = paramss; mCircles[i].SetBackgroundDrawable(Resources.GetDrawable(circles.GetResourceId(colorIndex, -1))); colorIndex++; if (colorIndex >= circles.Length()) { colorIndex = 0; } mRootView.AddView(mCircles[i], 0); } circles.Recycle(); /* Animations! */ SpringSystem springSystem = SpringSystem.Create(); // create spring Spring spring = springSystem.CreateSpring(); // add listeners along arc double arc = 2 * Math.PI / mCircles.Length; for (int i = 0; i < mCircles.Length; i++) { View view = mCircles[i]; // map spring to a line segment from the center to the edge of the ring spring.AddListener(new MapPerformer(view, ViewHelper.TranslationX, 0, 1, 0, (float)(RING_DIAMETER * Math.Cos(i * arc)))); spring.AddListener(new MapPerformer(view, ViewHelper.TranslationY, 0, 1, 0, (float)(RING_DIAMETER * Math.Sin(i * arc)))); spring.SetEndValue(CLOSED); } ToggleImitator imitator = new ToggleImitator(spring, CLOSED, OPEN); // move circle using finger, snap when near another circle, and bloom when touched new Actor.Builder(SpringSystem.Create(), mCircle) .AddMotion(new SnapImitator(MotionProperty.X), ViewHelper.TranslationX) .AddMotion(new SnapImitator(MotionProperty.Y), ViewHelper.TranslationY) .OnTouchListener(imitator) .Build(); return(mRootView); }