当前位置: 首页>>代码示例>>C#>>正文


C# Canvas.SaveLayerAlpha方法代码示例

本文整理汇总了C#中Android.Graphics.Canvas.SaveLayerAlpha方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.SaveLayerAlpha方法的具体用法?C# Canvas.SaveLayerAlpha怎么用?C# Canvas.SaveLayerAlpha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Android.Graphics.Canvas的用法示例。


在下文中一共展示了Canvas.SaveLayerAlpha方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnDraw

			protected override void OnDraw (Canvas canvas)
			{
				canvas.DrawColor (Color.White);

				canvas.Translate (10, 10);

				canvas.SaveLayerAlpha (0, 0, 200, 200, 0x88, SaveFlags.All);

				mPaint.Color = Color.Red;
				canvas.DrawCircle (75, 75, 75, mPaint);
				mPaint.Color = Color.Blue;
				canvas.DrawCircle (125, 125, 75, mPaint);

				canvas.Restore ();
			}
开发者ID:89sos98,项目名称:monodroid-samples,代码行数:15,代码来源:Layers.cs

示例2: draw

			public void draw(Canvas canvas) {
				int width = mBounds.Width ();
				int height = mBounds.Height();
				int cx = width / 2;
				int cy = height / 2;
				Boolean drawTriggerWhileFinishing = false;
				int restoreCount = canvas.Save();
				canvas.ClipRect(mBounds);

				if (mRunning || (mFinishTime > 0)) {
					long now = AnimationUtils.CurrentAnimationTimeMillis();
					long elapsed = (now - mStartTime) % ANIMATION_DURATION_MS;
					long iterations = (now - mStartTime) / ANIMATION_DURATION_MS;
					float rawProgress = (elapsed / (ANIMATION_DURATION_MS / 100f));

					// If we're not running anymore, that means we're running through
					// the finish animation.
					if (!mRunning) {
						// If the finish animation is done, don't draw anything, and
						// don't repost.
						if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) {
							mFinishTime = 0;
							return;
						}

						// Otherwise, use a 0 opacity alpha layer to clear the animation
						// from the inside out. This layer will prevent the circles from
						// drawing within its bounds.
						long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS;
						float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f));
						float pct = (finishProgress / 100f);
						// Radius of the circle is half of the screen.
						float clearRadius = width / 2;//* INTERPOLATOR.getInterpolation(pct);
						mClipRect.Set(cx - clearRadius, 0, cx + clearRadius, height);
						canvas.SaveLayerAlpha(mClipRect, 0, 0);
						// Only draw the trigger if there is a space in the center of
						// this refreshing view that needs to be filled in by the
						// trigger. If the progress view is just still animating, let it
						// continue animating.
						drawTriggerWhileFinishing = true;
					}

					// First fill in with the last color that would have finished drawing.
					if (iterations == 0) {
						canvas.DrawColor (Android.Graphics.Color.Blue);
					} else {
						if (rawProgress >= 0 && rawProgress < 25) {
							canvas.DrawColor(Android.Graphics.Color.AliceBlue);
						} else if (rawProgress >= 25 && rawProgress < 50) {
							canvas.DrawColor (Android.Graphics.Color.Blue);
						} else if (rawProgress >= 50 && rawProgress < 75) {
							canvas.DrawColor (Android.Graphics.Color.BlueViolet);
						} else {
							canvas.DrawColor (Android.Graphics.Color.CadetBlue);
						}
					}

					// Then draw up to 4 overlapping concentric circles of varying radii, based on how far
					// along we are in the cycle.
					// progress 0-50 draw mColor2
					// progress 25-75 draw mColor3
					// progress 50-100 draw mColor4
					// progress 75 (wrap to 25) draw mColor1
					if ((rawProgress >= 0 && rawProgress <= 25)) {
						float pct = (((rawProgress + 25) * 2) / 100f);
						drawCircle(canvas, cx, cy, mColor1, pct);
					}
					if (rawProgress >= 0 && rawProgress <= 50) {
						float pct = ((rawProgress * 2) / 100f);
						drawCircle(canvas, cx, cy, mColor2, pct);
					}
					if (rawProgress >= 25 && rawProgress <= 75) {
						float pct = (((rawProgress - 25) * 2) / 100f);
						drawCircle(canvas, cx, cy, mColor3, pct);
					}
					if (rawProgress >= 50 && rawProgress <= 100) {
						float pct = (((rawProgress - 50) * 2) / 100f);
						drawCircle(canvas, cx, cy, mColor4, pct);
					}
					if ((rawProgress >= 75 && rawProgress <= 100)) {
						float pct = (((rawProgress - 75) * 2) / 100f);
						drawCircle(canvas, cx, cy, mColor1, pct);
					}
					if (mTriggerPercentage > 0 && drawTriggerWhileFinishing) {
						// There is some portion of trigger to draw. Restore the canvas,
						// then draw the trigger. Otherwise, the trigger does not appear
						// until after the bar has finished animating and appears to
						// just jump in at a larger width than expected.
						canvas.RestoreToCount(restoreCount);
						restoreCount = canvas.Save();
						canvas.ClipRect(mBounds);
						drawTrigger(canvas, cx, cy);
					}
					// Keep running until we finish out the last cycle.
					ViewCompat.PostInvalidateOnAnimation(mParent);
				} else {
					// Otherwise if we're in the middle of a trigger, draw that.
					if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) {
						drawTrigger(canvas, cx, cy);
					}
//.........这里部分代码省略.........
开发者ID:jeedey93,项目名称:xamarin-android-samples,代码行数:101,代码来源:ActionProcessButton.cs


注:本文中的Android.Graphics.Canvas.SaveLayerAlpha方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。