@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { this.innerView.measure(widthMeasureSpec, heightMeasureSpec); ImageView iv1 = (ImageView) this.innerView.findViewById(R.id.top_item_1); LayoutParams lp = iv1.getLayoutParams(); lp.height = iv1.getMeasuredWidth(); iv1.setLayoutParams(lp); ImageView iv2 = (ImageView) this.innerView.findViewById(R.id.top_item_2); lp = iv2.getLayoutParams(); lp.height = iv2.getMeasuredWidth(); iv2.setLayoutParams(lp); ImageView iv3 = (ImageView) this.innerView.findViewById(R.id.top_item_3); lp = iv3.getLayoutParams(); lp.height = iv3.getMeasuredWidth(); iv3.setLayoutParams(lp); TextView tv = (TextView) this.innerView.findViewById(R.id.top_item_others); lp = tv.getLayoutParams(); lp.height = iv3.getMeasuredWidth(); tv.setLayoutParams(lp); this.innerView.measure(widthMeasureSpec, heightMeasureSpec); this.setMeasuredDimension( this.innerView.getMeasuredWidth(), this.innerView.getMeasuredHeight()); }
private void onPanelDragged(int newTop) { mLastNotDraggingSlideState = mSlideState; mSlideState = PanelState.DRAGGING; // Recompute the slide offset based on the new top position mSlideOffset = computeSlideOffset(newTop); applyParallaxForCurrentSlideOffset(); // Dispatch the slide event dispatchOnPanelSlide(mSlideableView); // If the slide offset is negative, and overlay is not on, we need to // increase the // height of the main content LayoutParams lp = (LayoutParams) mMainView.getLayoutParams(); int defaultHeight = getHeight() - getPaddingBottom() - getPaddingTop() - mPanelHeight; if (mSlideOffset <= 0 && !mOverlayContent) { // expand the main view lp.height = mIsSlidingUp ? (newTop - getPaddingBottom()) : (getHeight() - getPaddingBottom() - mSlideableView.getMeasuredHeight() - newTop); mMainView.requestLayout(); } else if (lp.height != defaultHeight && !mOverlayContent) { lp.height = defaultHeight; mMainView.requestLayout(); } }
private void init() { setOrientation(LinearLayout.VERTICAL); textView = new TextView(getContext()); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); textView.setTextColor(0xff3b84c0); addView(textView); LayoutParams layoutParams = (LayoutParams) textView.getLayoutParams(); layoutParams.width = LayoutParams.WRAP_CONTENT; layoutParams.height = LayoutParams.WRAP_CONTENT; layoutParams.leftMargin = AndroidUtilities.dp(8); layoutParams.rightMargin = AndroidUtilities.dp(8); layoutParams.topMargin = AndroidUtilities.dp(6); layoutParams.bottomMargin = AndroidUtilities.dp(4); if (LocaleController.isRTL) { textView.setGravity(Gravity.RIGHT); layoutParams.gravity = Gravity.RIGHT; } textView.setLayoutParams(layoutParams); View view = new View(getContext()); view.setBackgroundColor(0xff6caae4); addView(view); layoutParams = (LayoutParams) view.getLayoutParams(); layoutParams.weight = LayoutParams.MATCH_PARENT; layoutParams.height = AndroidUtilities.dp(1); view.setLayoutParams(layoutParams); }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int itemWidth; if (AndroidUtilities.isTablet()) { itemWidth = (AndroidUtilities.dp(490) - ((albumsCount + 1) * AndroidUtilities.dp(4))) / albumsCount; } else { itemWidth = (AndroidUtilities.displaySize.x - ((albumsCount + 1) * AndroidUtilities.dp(4))) / albumsCount; } for (int a = 0; a < albumsCount; a++) { LayoutParams layoutParams = (LayoutParams) albumViews[a].getLayoutParams(); layoutParams.topMargin = AndroidUtilities.dp(4); layoutParams.leftMargin = (itemWidth + AndroidUtilities.dp(4)) * a; layoutParams.width = itemWidth; layoutParams.height = itemWidth; layoutParams.gravity = Gravity.LEFT | Gravity.TOP; albumViews[a].setLayoutParams(layoutParams); } super.onMeasure( widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(4) + itemWidth, MeasureSpec.EXACTLY)); }
private void addIconTabBådeTekstOgBillede( final int position, int resId, Bitmap res, String title) { FrameLayout tabfl = new FrameLayout(getContext()); if (Build.VERSION.SDK_INT > 11) tabfl.setLayoutTransition(new LayoutTransition()); ImageView tabi = new ImageView(getContext()); tabi.setContentDescription(title); if (res != null) { tabi.setImageBitmap(res); tabi.setScaleType(ImageView.ScaleType.CENTER_INSIDE); tabi.setAdjustViewBounds(true); } else { tabi.setImageResource(resId); } tabi.setVisibility(View.GONE); TextView tabt = new TextView(getContext()); tabt.setText(title); tabt.setTypeface(App.skrift_gibson); tabt.setGravity(Gravity.CENTER); tabt.setSingleLine(); tabfl.addView(tabi); tabfl.addView(tabt); LayoutParams lp = (LayoutParams) tabi.getLayoutParams(); lp.gravity = Gravity.CENTER; lp = (LayoutParams) tabt.getLayoutParams(); lp.width = lp.height = ViewGroup.LayoutParams.MATCH_PARENT; lp.gravity = Gravity.CENTER; addTab(position, tabfl); }
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { // TODO Auto-generated method stub if (changed) { int left = padNumber * itemWidth; int top = 0; int right = left + itemWidth; int bottom = height; for (int i = 0; i < getChildCount(); i++) { ImageView imageView = (ImageView) getChildAt(i); LayoutParams imageViewLayoutParams = imageView.getLayoutParams(); imageViewLayoutParams.width = itemWidth; imageViewLayoutParams.height = height; // Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap(); Bitmap bitmap = bitmapList.get(i); if (bitmap != null) { Bitmap reflectedBitmap = getReflectedBitmap(bitmap); imageView.setImageBitmap(reflectedBitmap); } imageView.setLayoutParams(imageViewLayoutParams); left = itemWidth * (i + padNumber); right = left + itemWidth; imageView.layout(left, top, right, bottom); if (i < middleIndex) { imageView.setRotationY(ROTATE_DEGREE); } else if (i == middleIndex) { imageView.setRotationY(0); } else { imageView.setRotationY(-ROTATE_DEGREE); } } } }
private void forceUniformWidth(int count, int heightMeasureSpec) { int uniformMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), EditorInfo.IME_FLAG_NO_ENTER_ACTION); for (int i = SHOW_DIVIDER_NONE; i < count; i += VERTICAL) { View child = getVirtualChildAt(i); if (child.getVisibility() != 8) { LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp.width == -1) { int oldHeight = lp.height; lp.height = child.getMeasuredHeight(); measureChildWithMargins( child, uniformMeasureSpec, SHOW_DIVIDER_NONE, heightMeasureSpec, SHOW_DIVIDER_NONE); lp.height = oldHeight; } } } }
public void setMenuHeight(int measuredHeight) { Log.i("byz", "pos = " + position + ", height = " + measuredHeight); LayoutParams params = (LayoutParams) mMenuView.getLayoutParams(); if (params.height != measuredHeight) { params.height = measuredHeight; mMenuView.setLayoutParams(mMenuView.getLayoutParams()); } }
/** * 回弹设置高度 * * @param height */ public void setSmoothExHeight(int height) { LayoutParams lp = (LayoutParams) container.getLayoutParams(); lp.height = height; if (mScroller.isFinished()) { if (lp.height <= 0) { lp.height = 0; if (mPullType == PullType.PULL_COMPLETE) { mPullType = PullType.PULL_IDLE; } } else if (mPullDownImpl != null && mPullType != PullType.PULL_LOADING) { // 正在加载数据 mPullType = PullType.PULL_LOADING; mPullDownImpl.onPullDown(); } } container.setLayoutParams(lp); }
public void show() { mArrow.clearAnimation(); mArrow.setVisibility(View.GONE); mLoaderTips.setText(R.string.g_pull_up_for_more); LayoutParams lp = (LayoutParams) mFooter.getLayoutParams(); lp.height = LayoutParams.WRAP_CONTENT; mFooter.setLayoutParams(lp); }
public void setFooterHeight(int height) { if (height <= 0) { height = 0; } LayoutParams lp = (LayoutParams) mFooter.getLayoutParams(); lp.height = height; mFooter.setLayoutParams(lp); }
private static void setSize(BridgeContext context, View view, int orientation, int size) { size *= context.getMetrics().density; LayoutParams layoutParams = (LayoutParams) view.getLayoutParams(); if (orientation == HORIZONTAL) { layoutParams.width = size; } else { layoutParams.height = size; } view.setLayoutParams(layoutParams); }
/** * Show this SnackBar. Make sure it already attached to a parent view or this method will do * nothing. */ public void show() { ViewGroup parent = (ViewGroup) getParent(); if (parent == null || mState == STATE_SHOWING || mState == STATE_DISMISSING) return; if (parent instanceof FrameLayout) { LayoutParams params = (LayoutParams) getLayoutParams(); params.width = mWidth; params.height = mHeight; params.gravity = Gravity.START | Gravity.BOTTOM; if (mIsRtl) params.rightMargin = mMarginStart; else params.leftMargin = mMarginStart; params.bottomMargin = mMarginBottom; } else if (parent instanceof RelativeLayout) { RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams(); params.width = mWidth; params.height = mHeight; params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); params.addRule(RelativeLayout.ALIGN_PARENT_START); if (mIsRtl) params.rightMargin = mMarginStart; else params.leftMargin = mMarginStart; params.bottomMargin = mMarginBottom; } if (mInAnimationId != 0 && mState != STATE_SHOWN) { Animation anim = AnimationUtils.loadAnimation(getContext(), mInAnimationId); anim.setAnimationListener( new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { setState(STATE_SHOWING); setVisibility(View.VISIBLE); } @Override public void onAnimationRepeat(Animation animation) {} @Override public void onAnimationEnd(Animation animation) { setState(STATE_SHOWN); startTimer(); } }); startAnimation(anim); } else { setVisibility(View.VISIBLE); setState(STATE_SHOWN); startTimer(); } }
@Override public View getView(int pos, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(mContext).inflate(R.layout.mgr_menu_listview, null); } RelativeLayout l = (RelativeLayout) convertView.findViewById(R.id.mgr_item_lay); LayoutParams lp = (LayoutParams) l.getLayoutParams(); if (pos == 3) { lp.height = (int) getResources().getDimension(R.dimen.mgr_menu_specific_height); l.setLayoutParams(lp); } else { lp.height = (int) getResources().getDimension(R.dimen.mgr_menu_list_height); l.setLayoutParams(lp); } TextView text = (TextView) convertView.findViewById(R.id.mgr_menu_item); text.setText(mMenuArr[pos]); return convertView; }
/** * 手指滑动设置高度 * * @param height */ public void setExHeight(int height) { LayoutParams lp = (LayoutParams) container.getLayoutParams(); lp.height += height; if (lp.height <= 0) { // mPullType = PullType.PULL_IDLE; lp.height = 0; } else if (mPullType != PullType.PULL_COMPLETE && mPullType != PullType.PULL_LOADING) { // 未完成下拉 if (mPullType != PullType.PULL_READY && lp.height < mDefaultHeight) { // 回退 mPullType = PullType.PULL_READY; // 下拉刷新 tv_content.setText(R.string.header_content_ready); } else if (mPullType != PullType.PULL_DOWN && lp.height >= mDefaultHeight) { // 旋转 mPullType = PullType.PULL_DOWN; // 释放立即刷新 tv_content.setText(R.string.header_content_pulldown); } } container.setLayoutParams(lp); }
/** * Depending on whether the security is up, the widget size needs to change * * @param height The height of the widget, -1 for full height */ private void setWidgetHeight(int height) { boolean needLayout = false; View widget = getContent(); if (widget != null) { LayoutParams lp = (LayoutParams) widget.getLayoutParams(); if (lp.height != height) { needLayout = true; lp.height = height; } } if (needLayout) { requestLayout(); } }
@Override public boolean onScale(ScaleGestureDetector scaleGestureDetector) { float spanX = scaleGestureDetector.getCurrentSpanX() - scaleGestureDetector.getPreviousSpanX(); float spanY = scaleGestureDetector.getCurrentSpanY() - scaleGestureDetector.getPreviousSpanY(); LayoutParams lParams = (LayoutParams) getLayoutParams(); float newWidth = lParams.width + spanX; float newHeight = lParams.height + spanY; lParams.width = (int) newWidth; lParams.height = (int) newHeight; setLayoutParams(lParams); Log.i("spanX", spanX + ""); Log.i("spanY", spanY + ""); return true; }
@Override public LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) { final LayoutParams spannableLp = new LayoutParams((MarginLayoutParams) lp); spannableLp.width = LayoutParams.MATCH_PARENT; spannableLp.height = LayoutParams.MATCH_PARENT; if (lp instanceof LayoutParams) { final LayoutParams other = (LayoutParams) lp; if (isVertical()) { spannableLp.colSpan = Math.max(1, Math.min(other.colSpan, getLaneCount())); spannableLp.rowSpan = Math.max(1, other.rowSpan); } else { spannableLp.colSpan = Math.max(1, other.colSpan); spannableLp.rowSpan = Math.max(1, Math.min(other.rowSpan, getLaneCount())); } } return spannableLp; }
protected final void refreshRefreshableViewSize(int width, int height) { // We need to set the Height of the Refreshable View to the same as // this layout LayoutParams lp = (LayoutParams) mRefreshableViewWrapper.getLayoutParams(); switch (getPullToRefreshScrollDirection()) { case HORIZONTAL: if (lp.width != width) { lp.width = width; mRefreshableViewWrapper.requestLayout(); } break; case VERTICAL: if (lp.height != height) { lp.height = height; mRefreshableViewWrapper.requestLayout(); } break; } }
private LayoutParams initParams(View view, int left, int top) { int[] loc = new int[2]; getLocationOnScreen(loc); final LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); left -= loc[0]; top -= loc[1]; layoutParams.leftMargin = left; layoutParams.topMargin = top; view.setLeft(left); view.setTop(top); if (view.getMeasuredWidth() != 0) { layoutParams.width = view.getMeasuredWidth(); view.setRight(left + layoutParams.width); } if (view.getMeasuredHeight() != 0) { layoutParams.height = view.getMeasuredHeight(); view.setBottom(top + layoutParams.height); } return layoutParams; }
public void handleCompletion() { removeAllViews(); TextView label = new TextView(this.getContext()); label.setText("Great work!!"); getVocabBlasterActivity().formatHandwritingOnAChalkboard(label); addView(label); label = new TextView(this.getContext()); label.setText("You have these words pretty well mastered."); getVocabBlasterActivity().formatHandwritingOnAChalkboard(label); Button button = new Button(this.getContext()); button.setText("Start Over"); button.setTextColor(Color.BLACK); LayoutParams layoutParams = new LayoutParams(); layoutParams.weight = 1.0f; float density = getResources().getDisplayMetrics().density; layoutParams.width = (int) (150 * density); layoutParams.topMargin = 60; layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT; layoutParams.gravity = Gravity.CENTER_HORIZONTAL; button.setLayoutParams(layoutParams); final AdministerTestActivity vocabBlaster = (AdministerTestActivity) this.getContext(); button.setOnClickListener( new OnClickListener() { public void onClick(View view) { vocabBlaster.reset(); } }); addView(label); addView(button); }
/** show footer */ public void show() { LayoutParams lp = (LayoutParams) mContentView.getLayoutParams(); lp.height = LayoutParams.WRAP_CONTENT; mContentView.setLayoutParams(lp); }
/** hide footer when disable pull load more */ public void hide() { LayoutParams lp = (LayoutParams) mContentView.getLayoutParams(); lp.height = 0; mContentView.setLayoutParams(lp); }
protected void showOperation(int positionY) { final MagazineLoaderActivity activity = (MagazineLoaderActivity) context; int height = activity.getWindowManager().getDefaultDisplay().getHeight(); int width = activity.getWindowManager().getDefaultDisplay().getWidth(); final ViewGroup floatLayer = (ViewGroup) activity.getLayoutInflater().inflate(R.layout.topmenu, null); floatLayer.setVisibility(View.VISIBLE); floatLayer.setBackgroundColor(Color.BLACK); floatLayer.setAlpha((float) 0.5); ImageButton backhomeBtn = (ImageButton) floatLayer.findViewById(R.id.backHomeBtn); backhomeBtn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { activity.finish(); } }); ImageButton categoryBtn = (ImageButton) floatLayer.findViewById(R.id.catetoryBtn); categoryBtn.setOnClickListener( new View.OnClickListener() { private Gallery gallery; @Override public void onClick(View v) { // gallery=(Gallery) floatLayer.findViewById(R.id.gallery1); // gallery=new Gallery(activity); // gallery.setAdapter(new MagazinePageAdapter(activity, activity.getMagazine())); // gallery.setVisibility(View.VISIBLE); GalleryPageView pageView = new GalleryPageView(activity); floatLayer.addView(pageView); } }); int position = (positionY / height) * height; LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.setMargins(0, position, 0, 0); params.height = height; params.width = width; params.width = activity.getWindowManager().getDefaultDisplay().getWidth(); floatLayer.setClickable(true); floatLayer.setOnTouchListener( new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { v.getParent().requestDisallowInterceptTouchEvent(true); if (event.getAction() == MotionEvent.ACTION_UP) { int childCount = floatLayer.getChildCount(); for (int i = 0; i < childCount; i++) { View child = floatLayer.getChildAt(i); if (child instanceof GalleryPageView) { GalleryPageView pager = (GalleryPageView) child; pager.recycle(); } } floatLayer.setVisibility(View.GONE); } return false; } }); getFrameLayout().addView(floatLayer, params); }
/** Sets the size of the icon and the spacing between it and the message. */ public void setIconSizeAndSpacing(int width, int height, int iconMessageSpacing) { LayoutParams lp = (LayoutParams) mIconView.getLayoutParams(); lp.width = width; lp.height = height; lp.endMargin = iconMessageSpacing; }
public void setVisiableHeight(int height) { if (height < 0) height = 0; LayoutParams lp = (LayoutParams) mContainer.getLayoutParams(); lp.height = height; mContainer.setLayoutParams(lp); }
private void adaptLayoutParameters() { int count = getChildCount(); for (int i = 0; i < count; i++) { final View child = getChildAt(i); final LayoutParams childParams = (LayoutParams) child.getLayoutParams(); int[] relations = childParams.getRelations(); if (childParams.getWidthWeight() > 0 && childParams.width != LayoutParams.WRAP_CONTENT) { throw new IllegalArgumentException( "widthWeight > 0 not supported for layout_width != WRAP_CONTENT in View: " + child); } if (childParams.getHeightWeight() > 0 && childParams.height != LayoutParams.WRAP_CONTENT) { throw new IllegalArgumentException( "heightWeight > 0 not supported for layout_height != WRAP_CONTENT in View: " + child); } // If view is aligned both to parent's top and bottom (left and // right) then its height (width) is MATCH_PARENT and the other way // around if (relations[ALIGN_PARENT_TOP] != 0 && relations[ALIGN_PARENT_BOTTOM] != 0) { childParams.height = LayoutParams.MATCH_PARENT; } else if (childParams.height == LayoutParams.MATCH_PARENT) { relations[ALIGN_PARENT_TOP] = relations[ALIGN_PARENT_BOTTOM] = TRUE; } if (relations[ALIGN_PARENT_LEFT] != 0 && relations[ALIGN_PARENT_RIGHT] != 0) { childParams.width = LayoutParams.MATCH_PARENT; } else if (childParams.width == LayoutParams.MATCH_PARENT) { relations[ALIGN_PARENT_LEFT] = relations[ALIGN_PARENT_RIGHT] = TRUE; } if (relations[ALIGN_PARENT_TOP] == TRUE) { relations[ALIGN_TOP] = PARENT; } if (relations[ALIGN_PARENT_BOTTOM] == TRUE) { relations[ALIGN_BOTTOM] = PARENT; } if (relations[ALIGN_PARENT_LEFT] == TRUE) { relations[ALIGN_LEFT] = PARENT; } if (relations[ALIGN_PARENT_RIGHT] == TRUE) { relations[ALIGN_RIGHT] = PARENT; } if (relations[ALIGN_CENTER] != 0) { relations[ALIGN_CENTER_HORIZONTALLY] = relations[ALIGN_CENTER]; relations[ALIGN_CENTER_VERTICALLY] = relations[ALIGN_CENTER]; } if (relations[CENTER_IN_PARENT] == TRUE) { relations[CENTER_HORIZONTAL] = relations[CENTER_VERTICAL] = TRUE; } if (relations[CENTER_HORIZONTAL] == TRUE) { relations[ALIGN_CENTER_HORIZONTALLY] = PARENT; } if (relations[CENTER_VERTICAL] == TRUE) { relations[ALIGN_CENTER_VERTICALLY] = PARENT; } if (!hasHorizontalRelations(relations)) { relations[ALIGN_LEFT] = PARENT; } if (!hasVerticalRelations(relations)) { relations[ALIGN_TOP] = PARENT; } } }
void measureVertical(int widthMeasureSpec, int heightMeasureSpec) { boolean matchWidthLocally; int measuredWidth; this.mTotalLength = SHOW_DIVIDER_NONE; int maxWidth = SHOW_DIVIDER_NONE; int childState = SHOW_DIVIDER_NONE; int alternativeMaxWidth = SHOW_DIVIDER_NONE; int weightedMaxWidth = SHOW_DIVIDER_NONE; boolean allFillParent = true; float totalWeight = 0.0f; int count = getVirtualChildCount(); int widthMode = MeasureSpec.getMode(widthMeasureSpec); int heightMode = MeasureSpec.getMode(heightMeasureSpec); boolean matchWidth = false; boolean skippedMeasure = false; int baselineChildIndex = this.mBaselineAlignedChildIndex; boolean useLargestChild = this.mUseLargestChild; int largestChildHeight = RtlSpacingHelper.UNDEFINED; int i = SHOW_DIVIDER_NONE; while (i < count) { LayoutParams lp; int totalLength; int childHeight; int margin; View child = getVirtualChildAt(i); if (child == null) { this.mTotalLength += measureNullChild(i); } else if (child.getVisibility() == 8) { i += getChildrenSkipCount(child, i); } else { if (hasDividerBeforeChildAt(i)) { this.mTotalLength += this.mDividerHeight; } lp = (LayoutParams) child.getLayoutParams(); totalWeight += lp.weight; if (heightMode == 1073741824 && lp.height == 0 && lp.weight > 0.0f) { totalLength = this.mTotalLength; this.mTotalLength = Math.max(totalLength, (lp.topMargin + totalLength) + lp.bottomMargin); skippedMeasure = true; } else { int oldHeight = RtlSpacingHelper.UNDEFINED; if (lp.height == 0 && lp.weight > 0.0f) { oldHeight = SHOW_DIVIDER_NONE; lp.height = -2; } measureChildBeforeLayout( child, i, widthMeasureSpec, SHOW_DIVIDER_NONE, heightMeasureSpec, totalWeight == 0.0f ? this.mTotalLength : SHOW_DIVIDER_NONE); if (oldHeight != Integer.MIN_VALUE) { lp.height = oldHeight; } childHeight = child.getMeasuredHeight(); totalLength = this.mTotalLength; this.mTotalLength = Math.max( totalLength, (((totalLength + childHeight) + lp.topMargin) + lp.bottomMargin) + getNextLocationOffset(child)); if (useLargestChild) { largestChildHeight = Math.max(childHeight, largestChildHeight); } } if (baselineChildIndex >= 0 && baselineChildIndex == i + VERTICAL) { this.mBaselineChildTop = this.mTotalLength; } if (i >= baselineChildIndex || lp.weight <= 0.0f) { matchWidthLocally = false; if (widthMode != 1073741824 && lp.width == -1) { matchWidth = true; matchWidthLocally = true; } margin = lp.leftMargin + lp.rightMargin; measuredWidth = child.getMeasuredWidth() + margin; maxWidth = Math.max(maxWidth, measuredWidth); childState = View.combineMeasuredStates(childState, child.getMeasuredState()); allFillParent = allFillParent && lp.width == -1; if (lp.weight > 0.0f) { if (!matchWidthLocally) { margin = measuredWidth; } weightedMaxWidth = Math.max(weightedMaxWidth, margin); } else { if (!matchWidthLocally) { margin = measuredWidth; } alternativeMaxWidth = Math.max(alternativeMaxWidth, margin); } i += getChildrenSkipCount(child, i); } else { throw new RuntimeException( "A child of LinearLayout with index less than mBaselineAlignedChildIndex has weight > 0, which won't work. Either remove the weight, or don't set mBaselineAlignedChildIndex."); } } i += VERTICAL; } if (this.mTotalLength > 0 && hasDividerBeforeChildAt(count)) { this.mTotalLength += this.mDividerHeight; } if (useLargestChild && (heightMode == Integer.MIN_VALUE || heightMode == 0)) { this.mTotalLength = SHOW_DIVIDER_NONE; i = SHOW_DIVIDER_NONE; while (i < count) { child = getVirtualChildAt(i); if (child == null) { this.mTotalLength += measureNullChild(i); } else if (child.getVisibility() == 8) { i += getChildrenSkipCount(child, i); } else { lp = (LayoutParams) child.getLayoutParams(); totalLength = this.mTotalLength; this.mTotalLength = Math.max( totalLength, (((totalLength + largestChildHeight) + lp.topMargin) + lp.bottomMargin) + getNextLocationOffset(child)); } i += VERTICAL; } } this.mTotalLength += this.mPaddingTop + this.mPaddingBottom; int heightSizeAndState = View.resolveSizeAndState( Math.max(this.mTotalLength, getSuggestedMinimumHeight()), heightMeasureSpec, SHOW_DIVIDER_NONE); int delta = (heightSizeAndState & View.MEASURED_SIZE_MASK) - this.mTotalLength; if (skippedMeasure || (delta != 0 && totalWeight > 0.0f)) { float weightSum; if (this.mWeightSum > 0.0f) { weightSum = this.mWeightSum; } else { weightSum = totalWeight; } this.mTotalLength = SHOW_DIVIDER_NONE; for (i = SHOW_DIVIDER_NONE; i < count; i += VERTICAL) { child = getVirtualChildAt(i); if (child.getVisibility() != 8) { lp = (LayoutParams) child.getLayoutParams(); float childExtra = lp.weight; if (childExtra > 0.0f) { int share = (int) ((((float) delta) * childExtra) / weightSum); weightSum -= childExtra; delta -= share; int childWidthMeasureSpec = ViewGroup.getChildMeasureSpec( widthMeasureSpec, ((this.mPaddingLeft + this.mPaddingRight) + lp.leftMargin) + lp.rightMargin, lp.width); if (lp.height == 0 && heightMode == 1073741824) { if (share <= 0) { share = SHOW_DIVIDER_NONE; } child.measure( childWidthMeasureSpec, MeasureSpec.makeMeasureSpec(share, EditorInfo.IME_FLAG_NO_ENTER_ACTION)); } else { childHeight = child.getMeasuredHeight() + share; if (childHeight < 0) { childHeight = SHOW_DIVIDER_NONE; } child.measure( childWidthMeasureSpec, MeasureSpec.makeMeasureSpec(childHeight, EditorInfo.IME_FLAG_NO_ENTER_ACTION)); } childState = View.combineMeasuredStates( childState, child.getMeasuredState() & InputDevice.SOURCE_ANY); } margin = lp.leftMargin + lp.rightMargin; measuredWidth = child.getMeasuredWidth() + margin; maxWidth = Math.max(maxWidth, measuredWidth); matchWidthLocally = widthMode != 1073741824 && lp.width == -1; if (!matchWidthLocally) { margin = measuredWidth; } alternativeMaxWidth = Math.max(alternativeMaxWidth, margin); allFillParent = allFillParent && lp.width == -1; totalLength = this.mTotalLength; this.mTotalLength = Math.max( totalLength, (((child.getMeasuredHeight() + totalLength) + lp.topMargin) + lp.bottomMargin) + getNextLocationOffset(child)); } } this.mTotalLength += this.mPaddingTop + this.mPaddingBottom; } else { alternativeMaxWidth = Math.max(alternativeMaxWidth, weightedMaxWidth); if (useLargestChild && heightMode != 1073741824) { for (i = SHOW_DIVIDER_NONE; i < count; i += VERTICAL) { child = getVirtualChildAt(i); if (!(child == null || child.getVisibility() == 8)) { if (((LayoutParams) child.getLayoutParams()).weight > 0.0f) { child.measure( MeasureSpec.makeMeasureSpec( child.getMeasuredWidth(), EditorInfo.IME_FLAG_NO_ENTER_ACTION), MeasureSpec.makeMeasureSpec( largestChildHeight, EditorInfo.IME_FLAG_NO_ENTER_ACTION)); } } } } } if (!(allFillParent || widthMode == 1073741824)) { maxWidth = alternativeMaxWidth; } setMeasuredDimension( View.resolveSizeAndState( Math.max( maxWidth + (this.mPaddingLeft + this.mPaddingRight), getSuggestedMinimumWidth()), widthMeasureSpec, childState), heightSizeAndState); if (matchWidth) { forceUniformWidth(count, heightMeasureSpec); } }