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


C# Rect.Contains方法代码示例

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


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

示例1: IsInIgnoredView

 private bool IsInIgnoredView(MotionEvent ev)
 {
     var rect = new Rect();
     foreach (var v in _ignoredViews)
     {
         v.GetHitRect(rect);
         if (rect.Contains((int) ev.GetX(), (int) ev.GetY()))
             return true;
     }
     return false;
 }
开发者ID:kobynet,项目名称:SlidingMenuSharp,代码行数:11,代码来源:CustomViewAbove.cs

示例2: IsHit

        private bool IsHit(Droppable droppable, int x, int y)
        {
            Rect hitRect = new Rect(0, 0, droppable.View.Width, droppable.View.Height);
            OffsetDescendantRectToMyCoords(droppable.View, hitRect);

            return hitRect.Contains(x, y);
        }
开发者ID:Cheesebaron,项目名称:MonoDroid.DragArea,代码行数:7,代码来源:DragArea.cs

示例3: OnTouchEvent

        public override bool OnTouchEvent(MotionEvent ev)
        {
            var hist = 0.0f;
            var deltaY = 0.0f;
            var listY = 0.0f;
            _historyEvent = ev;
            vT.AddMovement(ev);
            if (_overscrolling)
            {
                var firstOverscroll = _firstOverscroll;
                _firstOverscroll = false;
                    if (ev.Action == MotionEventActions.Move && ev.HistorySize >= 1)
                    {
                        hist = ev.GetHistoricalY(0, 0);
                        deltaY = ev.GetY() - hist;
                        listY = _listView.GetY();

                        if (_header != null)
                        {
                            var headerY = _header.GetY();
                            if (deltaY > 0)
                            {
                                
                                if ((int)Math.Ceiling(headerY) == (0))
                                {
                                    return _listView.DispatchTouchEvent(ev);
                                }

                                if (headerY + deltaY <= (0))
                                {
                                    UpdateHeaderPosition(deltaY);
                                    _listView.SetY(_listView.GetY() + deltaY);
                                    _listView.LayoutParameters.Height = (int)Math.Ceiling(_listView.LayoutParameters.Height + deltaY);
                                    _listView.Invalidate();
                                    return true;
                                }
                                if (headerY + deltaY > 0)
                                {
                                    deltaY = 0 - headerY;
                                    UpdateHeaderPosition(0 - headerY);
                                    _listView.SetY(_listView.GetY() + deltaY);
                                    _listView.LayoutParameters.Height = (int)Math.Ceiling(_listView.LayoutParameters.Height + deltaY);
                                    _listView.Invalidate();
                                    return true;
                                }
                            }
                            if (deltaY < 0)
                            {
                                _overscrolling = false;
                            }
                        }
                       

                        if (listY + deltaY <= 0)
                        {
                            deltaY = 0 - listY;
                            _overscrolling = false;
                        }
                        else if (deltaY > 0)
                        {
                            deltaY *= 0.4f;
                        }
                        Log.Info("OverScrollingIntercept", "{0}", deltaY);
                        _listView.SetY(_listView.GetY() + deltaY);
                        _lastHistory = ev.HistorySize;
                    }
                    else if (ev.Action == MotionEventActions.Up)
                    {
                        _overscrolling = false;
                        _lastHistory = 0;
                        _listView.Animate().Y(_header != null ? _header.Height : 0.0f).SetDuration(250).Start();
                    }
                

            Log.Info("Interceptor", "Overscrolling True");
                return true;
            }
            var hitRect = new Rect();
            _header.GetHitRect(hitRect);

            if (hitRect.Contains((int)Math.Ceiling(ev.GetX()), (int)Math.Ceiling(ev.GetY())))
            {
                return _header.DispatchTouchEvent(ev);
            }
            else
            {
                if (_header != null )
                {
                    var headerY = _header.GetY();
                    if (ev.Action == MotionEventActions.Move && ev.HistorySize >= 1)
                    {
                        hist = ev.GetHistoricalY(0, 0);
                        deltaY = ev.GetY() - hist;

                        if (deltaY < 0)
                        {
                            if ((int) Math.Ceiling(headerY) == (0 - _header.Height))
                            {
                                return _listView.DispatchTouchEvent(ev);
                            }
//.........这里部分代码省略.........
开发者ID:EckyZero,项目名称:Hashtagg,代码行数:101,代码来源:OverscrollListView.cs

示例4: OnDown

		bool OnDown (MotionEvent motionEvent)
		{
			if (_paused) {
				return false;
			}

			var rect = new Rect ();
			int childCount = _listView.ChildCount;

			var listViewCoords = new int[2];
			_listView.GetLocationOnScreen (listViewCoords);

			int x = (int)motionEvent.RawX - listViewCoords [0];
			int y = (int)motionEvent.RawY - listViewCoords [1];

			View child;

			for (int i = 0; i < childCount; i++) {
				child = _listView.GetChildAt (i);
				child.GetHitRect (rect);
				if (rect.Contains (x, y)) {
					_downView = child;
					break;
				}
			}

			if (_downView != null) {
				mDownX = motionEvent.RawX;
				mDownY = motionEvent.RawY;

				_downPosition = _listView.GetPositionForView (_downView);

				if (_dismissCommand.CanExecute (_downPosition)) {
					_velocityTracker = VelocityTracker.Obtain ();
					_velocityTracker.AddMovement (motionEvent);
				} else {
					_downView = null;
				}
			}

			return false;
		}
开发者ID:fatelord,项目名称:chgk,代码行数:42,代码来源:SwipeDismissListViewTouchListener.cs

示例5: DispatchTouchEvent

		public override bool DispatchTouchEvent(MotionEvent event1) {
			if (event1.Action == MotionEventActions.Down) {
				View v = this.CurrentFocus;
				if ( v is EditText) {
					Rect outRect = new Rect();
					v.GetGlobalVisibleRect(outRect);
					if (!outRect.Contains((int)event1.GetX(), (int)event1.GetY())) {
						v.ClearFocus();
						InputMethodManager imm = (InputMethodManager) GetSystemService(Context.InputMethodService);
						imm.HideSoftInputFromWindow(v.WindowToken, 0);
					}
				}
			}
			return base.DispatchTouchEvent( event1 );
		}
开发者ID:tuananh82vn,项目名称:DonDon,代码行数:15,代码来源:HomeActivity.cs

示例6: GetSampleContent

		public override View GetSampleContent (Android.Content.Context con)
		{
			
			dlgAlert = new AlertDialog.Builder(con);

			dlgAlert.SetTitle("Results");
			dlgAlert.SetPositiveButton("OK", (object sender, DialogClickEventArgs e) => 
				{
				});
			dlgAlert.SetCancelable(true);

			Title.Add ("Software");
			Title.Add ("Banking");
			Title.Add ("Media");
			Title.Add ("Medical");
			spinners = new Spinner(con);
			spinners.DropDownWidth = 500;
			spinners.SetBackgroundColor(Color.Gray);

			ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>
				(con, Android.Resource.Layout.SimpleSpinnerItem, Experience);
			dataAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
			spinners.Adapter = dataAdapter;

			Country.Add ("UAE");
			Country.Add ("Uruguay");
			Country.Add ("United States");
			Country.Add ("United Kingdom");
			Country.Add ("Ukraine");

			Experience.Add ("1");
			Experience.Add ("2");

			autoComplete1 = new SfAutoComplete(con);
			autoComplete2 = new SfAutoComplete(con);

			text1s = new TextView(con);
			text2s = new TextView(con);
			text3s = new TextView(con);
			text4s = new TextView(con);
			text6s = new TextView(con);

			text11 = new TextView(con);
			text22 = new TextView(con);
			text33 = new TextView(con);
			text44 = new TextView(con);
			text55 = new TextView(con);
			text66 = new TextView(con);
			text77 = new TextView(con);
			text88 = new TextView(con);

			buttons = new Button(con);
			buttons.SetWidth(ActionBar.LayoutParams.MatchParent);
			buttons.SetHeight(40);
			buttons.Text = "Search";
			buttons.SetTextColor(Color.White);
			buttons.SetBackgroundColor(Color.Gray);
			buttons.Click += (object sender, EventArgs e) => {
				GetResult();
				//dlgAlert.SetMessage(count + " Jobs Found");
				dlgAlert.SetMessage (cc + " Jobs Found");
				dlgAlert.Create ().Show ();
			};
			text11.SetHeight(10);
			text22.SetHeight(30);
			text33.SetHeight(10);
			text44.SetHeight(30);
			text55.SetHeight(10);
			text66.SetHeight(30);
			text77.SetHeight(10);
			text88.SetHeight(30);

			text1s.Text = "Job Search";
			text1s.TextSize = 30;
			text1s.Typeface = Typeface.DefaultBold;
			text2s.Text = "Country";
			text2s.TextSize = 16;
			text3s.Text = "Job Field";
			text3s.TextSize = 16;
			text4s.Text = "Experience";
			text4s.TextSize = 16;
			text6s.SetHeight(40);

			ArrayAdapter<String> adapters = new ArrayAdapter<String>(con,
				Android.Resource.Layout.SimpleListItem1, new Countrylist().Country);
			autoComplete1.LayoutParameters = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 60);
			autoComplete1.SetAutoCompleteSource(adapters);
			autoComplete1.SuggestionMode = SuggestionMode.StartsWith;
			autoComplete1.MaximumDropDownHeight = 200;
			autoComplete1.Watermark = "Enter a country name";

			ArrayAdapter<String> adapters1 = new ArrayAdapter<String>(con,
				Android.Resource.Layout.SimpleListItem1, Title);
			autoComplete2.SetAutoCompleteSource(adapters1);
			autoComplete2.LayoutParameters = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 60);
			autoComplete2.SuggestionMode = SuggestionMode.Contains;
			autoComplete2.MaximumDropDownHeight = 200;
			autoComplete2.Watermark = "Starts with ’S’, ‘M’ or ‘B’";

			ArrayAdapter<String> adapters2 = new ArrayAdapter<String>(con,
//.........这里部分代码省略.........
开发者ID:IanLeatherbury,项目名称:tryfsharpforms,代码行数:101,代码来源:AutoComplete.cs

示例7: GetSampleContent


//.........这里部分代码省略.........
			periodValue.ValueChangeMode=ValueChangeMode.OnKeyFocus;
			periodValue.CultureInfo = culture;
			periodValue.AllowNull = true;

			periodStack.Orientation=Orientation.Horizontal;

			periodStack.AddView(period);
			periodStack.AddView(periodValue);

			layout.AddView(periodStack);



			/*
        OutPut values
         */

			LinearLayout outputStack = new LinearLayout(con);

			TextView outputtxt = new TextView(con);
			outputtxt.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100);
			outputtxt.Text="Interest";
			outputtxt.SetTextColor(Color.ParseColor("#66BB6A"));

			OutputNumbertxtBox =new SfNumericTextBox(con);
			OutputNumbertxtBox.FormatString="c";
			OutputNumbertxtBox.MaximumNumberDecimalDigits=0;
			OutputNumbertxtBox.AllowNull=true;
			OutputNumbertxtBox.CultureInfo = culture;
			OutputNumbertxtBox.Watermark="Enter Values";
			OutputNumbertxtBox.Clickable=false;
			OutputNumbertxtBox.Value = (float)(1000 * 0.1 * 20);
			OutputNumbertxtBox.Enabled=false;
			OutputNumbertxtBox.LayoutParameters=new ViewGroup.LayoutParams(width / 2, 100);
			OutputNumbertxtBox.ValueChangeMode=ValueChangeMode.OnLostFocus;


			outputStack.Orientation=Orientation.Horizontal;

			outputStack.AddView(outputtxt);
			outputStack.AddView(OutputNumbertxtBox);
			layout.AddView(outputStack);

			TextView dummy4 = new TextView(con);
			layout.SetPadding(20, 20, 10, 20);
			layout.AddView(dummy4);

			principalamount.ValueChanged+= (object sender, SfNumericTextBox.ValueChangedEventArgs e) => {
				if(!e.P1.ToString().Equals("")&&!periodValue.Value.ToString().Equals("")&&!Interestvalue.Value.ToString().Equals(""))
					OutputNumbertxtBox.Value=e.P1 * periodValue.Value *  Interestvalue.Value;

			};

			periodValue.ValueChanged+= (object sender, SfNumericTextBox.ValueChangedEventArgs e) => {
				if(!e.P1.ToString().Equals("")&&!principalamount.Value.ToString().Equals("")&&!Interestvalue.Value.ToString().Equals(""))
					OutputNumbertxtBox.Value=e.P1* principalamount.Value*Interestvalue.Value;

			};

			Interestvalue.ValueChanged+= (object sender, SfNumericTextBox.ValueChangedEventArgs e) => {
				if(!e.P1.ToString().Equals("")&&!principalamount.Value.ToString().Equals("")&&!periodValue.Value.ToString().Equals(""))
					OutputNumbertxtBox.Value=e.P1 * principalamount.Value *  periodValue.Value;

			};

			layout.Touch+= (object sender, View.TouchEventArgs e) => {
				if(OutputNumbertxtBox.IsFocused || Interestvalue.IsFocused ||periodValue.IsFocused || principalamount.IsFocused){
					Rect outRect = new Rect();
					OutputNumbertxtBox.GetGlobalVisibleRect(outRect);
					Interestvalue.GetGlobalVisibleRect(outRect);
					periodValue.GetGlobalVisibleRect(outRect);
					principalamount.GetGlobalVisibleRect(outRect);

					if (!outRect.Contains((int)e.Event.RawX, (int)e.Event.RawY)) {
						if(!OutputNumbertxtBox.Value.ToString().Equals(""))
							OutputNumbertxtBox.ClearFocus();
						if(!Interestvalue.Value.ToString().Equals(""))
							Interestvalue.ClearFocus();
						if(!periodValue.Value.ToString().Equals(""))
							periodValue.ClearFocus();
						if(!principalamount.Value.ToString().Equals(""))
							principalamount.ClearFocus();

					}
					hideSoftKeyboard((Activity)localcontext);
				}
			};






			frameLayout.AddView(layout);

			ScrollView scrollView = new ScrollView(con);
			scrollView.AddView(frameLayout);

			return scrollView;
		}
开发者ID:IanLeatherbury,项目名称:tryfsharpforms,代码行数:101,代码来源:NumericTextBox.cs

示例8: GetSelectedBarIndex

        private int GetSelectedBarIndex ( int x, int y)
        {
            var result = -1;
            var index = 0;

            foreach (var item in rows) {
                var area = new Rect ();
                item.BarView.GetHitRect (area);
                area.Top -= rowMargin;
                area.Bottom += rowMargin;
                area.Right = Right;
                if ( area.Contains ( x, y)) {
                    result = index;
                }
                index++;
            }
            return result;
        }
开发者ID:eatskolnikov,项目名称:mobile,代码行数:18,代码来源:BarChart.cs

示例9: DuplicateTouchEventForChildren

		/**
		 * Duplicate touch events to child views.
		 * We want to dispatch a down motion event and the move events to
		 * child views, but calling dispatchTouchEvent() causes StackOverflowError.
		 * Therefore we do it manually.
		 *
		 * @param ev            motion event to be passed to children
		 * @param pendingEvents pending events like ACTION_DOWN. This will be passed to the children before ev
		 */
		private void DuplicateTouchEventForChildren(MotionEvent ev, params MotionEvent[] pendingEvents)
		{
			if (ev == null)
			{
				return;
			}
			for (int i = ChildCount - 1; 0 <= i; i--)
			{
				View childView = GetChildAt(i);
				if (childView != null)
				{
					Rect childRect = new Rect();
					childView.GetHitRect(childRect);
					MotionEvent event2 = MotionEvent.ObtainNoHistory(ev);
					if (!childRect.Contains((int)event2.GetX(), (int)event2.GetY()))
					{
						continue;
					}
					float offsetX = -childView.Left;
					float offsetY = -childView.Top;
					bool consumed = false;
					if (pendingEvents != null)
					{
						foreach (MotionEvent pe in pendingEvents)
						{
							if (pe != null)
							{
								MotionEvent peAdjusted = MotionEvent.ObtainNoHistory(pe);
								peAdjusted.OffsetLocation(offsetX, offsetY);
								consumed |= childView.DispatchTouchEvent(peAdjusted);
							}
						}
					}
					event2.OffsetLocation(offsetX, offsetY);
					consumed |= childView.DispatchTouchEvent(event2);
					if (consumed)
					{
						break;
					}
				}
			}
		}
开发者ID:Julien-Mialon,项目名称:MaterialViewPager.Xamarin,代码行数:51,代码来源:TouchInterceptionFrameLayout.cs

示例10: OnTouchEvent

        public override bool OnTouchEvent(MotionEvent e)
        {
            CreateVelocityTracker(e);
            int curScrollX = this.ScrollX;
            // 检查触摸点是否在滑动布局(内容content)中,如果不是则返回false,即本View不处理该事件
            if (mContent != null && isTouchFinished)
            {
                Rect rect = new Rect();
                mContent.GetHitRect(rect);
                if (!rect.Contains((int)e.GetX() + curScrollX, (int)e.GetY()))
                {
                    return false;
                }
            }

            float x = e.GetX();    //取得本次event的X坐标
            switch (e.Action)
            {
                case MotionEventActions.Down:
                    mDownX = x;
                    mLastX = x;
                    isTouchFinished = false;
                    //			Log.v(TAG, "(Down)mDownX: " + x);
                    //			Log.v(TAG, "(Down)mLastX: " + x);
                    break;
                case MotionEventActions.Move:
                    //			Log.v(TAG, "(Move)mLastX: " + x);
                    int deltaX = (int)(mLastX - x);
                    if ((curScrollX + deltaX) < -mMaxScrollX)
                    {
                        deltaX = -mMaxScrollX - curScrollX;
                    }
                    if ((curScrollX + deltaX) > 0)
                    {
                        deltaX = -curScrollX;
                    }

                    if (deltaX != 0)
                    {
                        ScrollBy(deltaX, 0);
                    }
                    mLastX = x;
                    //			Log.v(TAG, "(Move)x: " + x);
                    break;
                case MotionEventActions.Up:
                    //			Log.v(TAG, "(Up)x: " + x);
                    //			Log.v(TAG, "(Up)mDownX: " + mDownX);
                    //			Log.v(TAG, "(Up)curScrollX: " + curScrollX);
                    int velocityX = GetScrollVelocity();
                    int offsetX = (int)(x - mDownX);

                    //成立表明移动距离已经达到被判断为滑动的最低标准
                    //不成立表明不被判断为滑动,则认为是单一的点击,则关闭menu
                    if (Math.Abs(offsetX) >= mTouchSlop)
                    {

                        //成立表明手指移动速度达标,则进行自动滑动;
                        //不成立表明速度不达标,但仍然需要判断当前SlideLayout的位置
                        //如果已经超过一半,则继续自动完成剩下的滑动,如果没有超过一半,则反向滑动
                        if (Math.Abs(velocityX) >= SNAP_VELOCITY)
                        {
                            if (velocityX > 0)
                            {
                                OpenMenu();
                            }
                            else if (velocityX < 0)
                            {
                                CloseMenu();
                            }
                        }
                        else
                        {
                            if (curScrollX >= -mMaxScrollX / 2)
                            {
                                CloseMenu();
                            }
                            else
                            {
                                OpenMenu();
                            }
                        }
                    }
                    else
                    {
                        CloseMenu();
                    }

                    RecycleVelocityTracker();
                    isTouchFinished = true;
                    break;
            }
            return true;
        }
开发者ID:Yi-shion,项目名称:Xamarin,代码行数:93,代码来源:MainActivity.cs

示例11: isInIgnoredView

 /**
  * If the motion event was relative to the view
  * which in ignored view list,return true;
  *
  * @param ev
  * @return
  */
 private bool isInIgnoredView(MotionEvent ev)
 {
     Rect rect = new Rect();
     foreach (View v in ignoredViews)
     {
         v.GetGlobalVisibleRect(rect);
         if (rect.Contains((int)ev.GetX(), (int)ev.GetY()))
             return true;
     }
     return false;
 }
开发者ID:skywolf888,项目名称:AndroidResideMenu.Net,代码行数:18,代码来源:ResideMenu.cs

示例12: findDownView

 /**
  * Returns the child {@link android.view.View} that was touched, by performing a hit test.
  *
  * @param motionEvent the {@link android.view.MotionEvent} to find the {@code View} for.
  *
  * @return the touched {@code View}, or {@code null} if none found.
  */
 //@Nullable
 private View findDownView(MotionEvent motionEvent)
 {
     Rect rect = new Rect();
     int childCount = mListViewWrapper.getChildCount();
     int x = (int)motionEvent.GetX();
     int y = (int)motionEvent.GetY();
     View downView = null;
     for (int i = 0; i < childCount && downView == null; i++)
     {
         View child = mListViewWrapper.getChildAt(i);
         if (child != null)
         {
             child.GetHitRect(rect);
             if (rect.Contains(x, y))
             {
                 downView = child;
             }
         }
     }
     return downView;
 }
开发者ID:skywolf888,项目名称:ListviewAnimations.Net,代码行数:29,代码来源:SwipeTouchListener.cs

示例13: IsWithinCircularBounds

        static bool IsWithinCircularBounds(Rect hit, Rect bounds)
        {
            if (!bounds.Contains(hit)) return false;

            // Forumula for a circle: (x-a)2 + (y-b)2 = r2
            var centerX = bounds.ExactCenterX() - bounds.Left;
            var centerY = bounds.ExactCenterY() - bounds.Top;
            var radius = centerX;

            double x = hit.Left - bounds.Left,
                   y = hit.Top - bounds.Top,
                   r2 = radius * radius,
                   xx = (x - centerX);

            var yy = Math.Sqrt(r2 - xx*xx) + 0.5;
            var upperBound = centerY - yy;
            var lowerBound = centerY + yy;

            var result = !Double.IsNaN (y) && y > upperBound && y < lowerBound;
            return result;
        }
开发者ID:sdhakal,项目名称:imageProject,代码行数:21,代码来源:MainActivity.cs


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