示例#1
0
		/// <summary>
		/// Add a view as a child and make sure it is measured (if necessary) and
		/// positioned properly.
		/// </summary>
		/// <remarks>
		/// Add a view as a child and make sure it is measured (if necessary) and
		/// positioned properly.
		/// </remarks>
		/// <param name="child">The view to add</param>
		/// <param name="position">The position of the view</param>
		/// <param name="y">The y position relative to which this view will be positioned</param>
		/// <param name="flow">
		/// if true, align top edge to y. If false, align bottom edge
		/// to y.
		/// </param>
		/// <param name="childrenLeft">Left edge where children should be positioned</param>
		/// <param name="selected">Is this position selected?</param>
		/// <param name="recycled">
		/// Has this view been pulled from the recycle bin? If so it
		/// does not need to be remeasured.
		/// </param>
		/// <param name="where">Where to add the item in the list</param>
		private void setupChild(android.view.View child, int position, int y, bool flow, 
			int childrenLeft, bool selected, bool recycled, int where)
		{
			bool isSelected_1 = selected && shouldShowSelector();
			bool updateChildSelected = isSelected_1 != child.isSelected();
			int mode = mTouchMode;
			bool isPressed_1 = mode > TOUCH_MODE_DOWN && mode < TOUCH_MODE_SCROLL && mMotionPosition
				 == position;
			bool updateChildPressed = isPressed_1 != child.isPressed();
			bool needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested(
				);
			// Respect layout params that are already in the view. Otherwise make
			// some up...
			android.widget.AbsListView.LayoutParams p = (android.widget.AbsListView.LayoutParams
				)child.getLayoutParams();
			if (p == null)
			{
				p = new android.widget.AbsListView.LayoutParams(android.view.ViewGroup.LayoutParams
					.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0);
			}
			p.viewType = mAdapter.getItemViewType(position);
			if (recycled && !p.forceAdd)
			{
				attachViewToParent(child, where, p);
			}
			else
			{
				p.forceAdd = false;
				addViewInLayout(child, where, p, true);
			}
			if (updateChildSelected)
			{
				child.setSelected(isSelected_1);
				if (isSelected_1)
				{
					requestFocus();
				}
			}
			if (updateChildPressed)
			{
				child.setPressed(isPressed_1);
			}
			if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null)
			{
				if (child is android.widget.Checkable)
				{
					((android.widget.Checkable)child).setChecked(mCheckStates.get(position));
				}
				else
				{
					if (getContext().getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES
						.HONEYCOMB)
					{
						child.setActivated(mCheckStates.get(position));
					}
				}
			}
			if (needToMeasure)
			{
				int childHeightSpec = android.view.ViewGroup.getChildMeasureSpec(android.view.View
					.MeasureSpec.makeMeasureSpec(0, android.view.View.MeasureSpec.UNSPECIFIED), 0, p
					.height);
				int childWidthSpec = android.view.ViewGroup.getChildMeasureSpec(android.view.View
					.MeasureSpec.makeMeasureSpec(mColumnWidth, android.view.View.MeasureSpec.EXACTLY
					), 0, p.width);
				child.measure(childWidthSpec, childHeightSpec);
			}
			else
			{
				cleanupLayoutState(child);
			}
			int w = child.getMeasuredWidth();
			int h = child.getMeasuredHeight();
			int childLeft;
			int childTop = flow ? y : y - h;
			int layoutDirection = getResolvedLayoutDirection();
			int absoluteGravity = android.view.Gravity.getAbsoluteGravity(mGravity, layoutDirection
				);
			switch (absoluteGravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK)
			{
				case android.view.Gravity.LEFT:
				{
					childLeft = childrenLeft;
					break;
				}

				case android.view.Gravity.CENTER_HORIZONTAL:
				{
					childLeft = childrenLeft + ((mColumnWidth - w) / 2);
					break;
				}

				case android.view.Gravity.RIGHT:
				{
					childLeft = childrenLeft + mColumnWidth - w;
					break;
				}

				default:
				{
					childLeft = childrenLeft;
					break;
				}
			}
			if (needToMeasure)
			{
				int childRight = childLeft + w;
				int childBottom = childTop + h;
				child.layout(childLeft, childTop, childRight, childBottom);
			}
			else
			{
				child.offsetLeftAndRight(childLeft - child.getLeft());
				child.offsetTopAndBottom(childTop - child.getTop());
			}
			if (mCachingStarted)
			{
				child.setDrawingCacheEnabled(true);
			}
			if (recycled && (((android.widget.AbsListView.LayoutParams)child.getLayoutParams(
				)).scrappedFromPosition) != position)
			{
				child.jumpDrawablesToCurrentState();
			}
		}
示例#2
0
		protected internal override void onMeasure(int widthMeasureSpec, int heightMeasureSpec
			)
		{
			// Sets up mListPadding
			base.onMeasure(widthMeasureSpec, heightMeasureSpec);
			int widthMode = android.view.View.MeasureSpec.getMode(widthMeasureSpec);
			int heightMode = android.view.View.MeasureSpec.getMode(heightMeasureSpec);
			int widthSize = android.view.View.MeasureSpec.getSize(widthMeasureSpec);
			int heightSize = android.view.View.MeasureSpec.getSize(heightMeasureSpec);
			if (widthMode == android.view.View.MeasureSpec.UNSPECIFIED)
			{
				if (mColumnWidth > 0)
				{
					widthSize = mColumnWidth + mListPadding.left + mListPadding.right;
				}
				else
				{
					widthSize = mListPadding.left + mListPadding.right;
				}
				widthSize += getVerticalScrollbarWidth();
			}
			int childWidth = widthSize - mListPadding.left - mListPadding.right;
			bool didNotInitiallyFit = determineColumns(childWidth);
			int childHeight = 0;
			int childState = 0;
			mItemCount = mAdapter == null ? 0 : mAdapter.getCount();
			int count = mItemCount;
			if (count > 0)
			{
				android.view.View child = obtainView(0, mIsScrap);
				android.widget.AbsListView.LayoutParams p = (android.widget.AbsListView.LayoutParams
					)child.getLayoutParams();
				if (p == null)
				{
					p = new android.widget.AbsListView.LayoutParams(android.view.ViewGroup.LayoutParams
						.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0);
					child.setLayoutParams(p);
				}
				p.viewType = mAdapter.getItemViewType(0);
				p.forceAdd = true;
				int childHeightSpec = getChildMeasureSpec(android.view.View.MeasureSpec.makeMeasureSpec
					(0, android.view.View.MeasureSpec.UNSPECIFIED), 0, p.height);
				int childWidthSpec = getChildMeasureSpec(android.view.View.MeasureSpec.makeMeasureSpec
					(mColumnWidth, android.view.View.MeasureSpec.EXACTLY), 0, p.width);
				child.measure(childWidthSpec, childHeightSpec);
				childHeight = child.getMeasuredHeight();
				childState = combineMeasuredStates(childState, child.getMeasuredState());
				if (mRecycler.shouldRecycleViewType(p.viewType))
				{
					mRecycler.addScrapView(child, -1);
				}
			}
			if (heightMode == android.view.View.MeasureSpec.UNSPECIFIED)
			{
				heightSize = mListPadding.top + mListPadding.bottom + childHeight + getVerticalFadingEdgeLength
					() * 2;
			}
			if (heightMode == android.view.View.MeasureSpec.AT_MOST)
			{
				int ourSize = mListPadding.top + mListPadding.bottom;
				int numColumns = mNumColumns;
				{
					for (int i = 0; i < count; i += numColumns)
					{
						ourSize += childHeight;
						if (i + numColumns < count)
						{
							ourSize += mVerticalSpacing;
						}
						if (ourSize >= heightSize)
						{
							ourSize = heightSize;
							break;
						}
					}
				}
				heightSize = ourSize;
			}
			if (widthMode == android.view.View.MeasureSpec.AT_MOST && mRequestedNumColumns !=
				 AUTO_FIT)
			{
				int ourSize = (mRequestedNumColumns * mColumnWidth) + ((mRequestedNumColumns - 1)
					 * mHorizontalSpacing) + mListPadding.left + mListPadding.right;
				if (ourSize > widthSize || didNotInitiallyFit)
				{
					widthSize |= MEASURED_STATE_TOO_SMALL;
				}
			}
			setMeasuredDimension(widthSize, heightSize);
			mWidthMeasureSpec = widthMeasureSpec;
		}