當前位置: 首頁>>代碼示例>>Java>>正文


Java MeasureSpec類代碼示例

本文整理匯總了Java中android.view.View.MeasureSpec的典型用法代碼示例。如果您正苦於以下問題:Java MeasureSpec類的具體用法?Java MeasureSpec怎麽用?Java MeasureSpec使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MeasureSpec類屬於android.view.View包,在下文中一共展示了MeasureSpec類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleHeader

import android.view.View.MeasureSpec; //導入依賴的package包/類
private int handleHeader(LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper,
    boolean layoutInVertical, int parentWidth, int parentHeight, int parentHPadding, int parentVPadding) {
    if (mHeader == null) {
        return 0;
    }
    OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();

    final ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(
        mHeader.getLayoutParams());

    // fill width
    int widthSpec = helper.getChildMeasureSpec(parentWidth - parentHPadding,
        layoutInVertical ? MATCH_PARENT : lp.width, !layoutInVertical);
    int heightSpec = helper.getChildMeasureSpec(parentHeight - parentVPadding,
        layoutInVertical ? lp.height : MeasureSpec.EXACTLY, layoutInVertical);
    helper.measureChildWithMargins(mHeader, widthSpec, heightSpec);
    return orientationHelper.getDecoratedMeasurement(mHeader);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:OnePlusNLayoutHelper.java

示例2: resolveView

import android.view.View.MeasureSpec; //導入依賴的package包/類
/**
 * Updates View bounds, possibly re-measuring and re-layouting it if the size changed.
 *
 * @param reactTag reactTag to lookup a View by
 * @param left left coordinate relative to parent
 * @param top top coordinate relative to parent
 * @param right right coordinate relative to parent
 * @param bottom bottom coordinate relative to parent
 */
/* package */ void updateViewBounds(int reactTag, int left, int top, int right, int bottom) {
  View view = resolveView(reactTag);
  int width = right - left;
  int height = bottom - top;
  if (view.getWidth() != width || view.getHeight() != height) {
    // size changed, we need to measure and layout the View
    view.measure(
        MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
        MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
    view.layout(left, top, right, bottom);
  } else {
    // same size, only location changed, there is a faster route.
    view.offsetLeftAndRight(left - view.getLeft());
    view.offsetTopAndBottom(top - view.getTop());
  }
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:26,代碼來源:FlatNativeViewHierarchyManager.java

示例3: onMeasure

import android.view.View.MeasureSpec; //導入依賴的package包/類
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    boolean lockedExpanded = widthMode == 1073741824;
    setFillViewport(lockedExpanded);
    int childCount = this.mTabLayout.getChildCount();
    if (childCount <= 1 || !(widthMode == 1073741824 || widthMode == Integer.MIN_VALUE)) {
        this.mMaxTabWidth = -1;
    } else if (childCount > 2) {
        this.mMaxTabWidth = (int) (((float) MeasureSpec.getSize(widthMeasureSpec)) * 0.4f);
    } else {
        this.mMaxTabWidth = MeasureSpec.getSize(widthMeasureSpec) / 2;
    }
    int oldWidth = getMeasuredWidth();
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int newWidth = getMeasuredWidth();
    if (lockedExpanded && oldWidth != newWidth) {
        setCurrentItem(this.mSelectedTabIndex);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:20,代碼來源:TabPageIndicator.java

示例4: measureViewHeight

import android.view.View.MeasureSpec; //導入依賴的package包/類
protected static int measureViewHeight(View view) {
    ViewGroup.LayoutParams p = view.getLayoutParams();
    if (p == null) {
        p = new ViewGroup.LayoutParams(MATCH_PARENT,WRAP_CONTENT);
    }
    int childHeightSpec;
    int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0, p.width);
    if (p.height > 0) {
        childHeightSpec = MeasureSpec.makeMeasureSpec(p.height, MeasureSpec.EXACTLY);
    } else {
        childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    }
    view.measure(childWidthSpec, childHeightSpec);
    return view.getMeasuredHeight();
}
 
開發者ID:penghuanliang,項目名稱:Rxjava2.0Demo,代碼行數:16,代碼來源:RefreshContentWrapper.java

示例5: setupChild

import android.view.View.MeasureSpec; //導入依賴的package包/類
public void setupChild(List<TabModelInterface> list) {
    if (list != null && list.size() != 0) {
        this.mTabList.clear();
        this.mTabList.addAll(list);
        this.tabStrip.removeAllViews();
        for (TabModelInterface model : list) {
            TextView textView = new TextView(getContext());
            textView.setGravity(17);
            textView.setText(model.getTabName());
            textView.setTextColor(getResources().getColor(R.color.du));
            textView.setTextSize(0, this.textSize);
            LayoutParams params = new LayoutParams(-2, -1);
            textView.setPadding(ViewUtils.dip2px(getContext(), 16.0f), 0, ViewUtils.dip2px
                    (getContext(), 16.0f), 0);
            textView.setOnClickListener(new InternalTabClickListener());
            this.tabStrip.addView(textView, params);
            textView.measure(MeasureSpec.makeMeasureSpec(0, 0), MeasureSpec.makeMeasureSpec
                    (0, 0));
        }
        initView();
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:23,代碼來源:BooheeTabLayout.java

示例6: handleHeader

import android.view.View.MeasureSpec; //導入依賴的package包/類
private int handleHeader(View header, LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper,
    boolean layoutInVertical, int parentWidth, int parentHeight, int parentHPadding, int parentVPadding) {
    if (header == null) {
        return 0;
    }
    OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();

    final ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(
        header.getLayoutParams());

    // fill width
    int widthSpec = helper.getChildMeasureSpec(parentWidth - parentHPadding,
        layoutInVertical ? MATCH_PARENT : lp.width, !layoutInVertical);
    int heightSpec = helper.getChildMeasureSpec(parentHeight - parentVPadding,
        layoutInVertical ? lp.height : MeasureSpec.EXACTLY, layoutInVertical);
    helper.measureChildWithMargins(header, widthSpec, heightSpec);
    return orientationHelper.getDecoratedMeasurement(header);
}
 
開發者ID:alibaba,項目名稱:vlayout,代碼行數:19,代碼來源:OnePlusNLayoutHelper.java

示例7: handleFooter

import android.view.View.MeasureSpec; //導入依賴的package包/類
private int handleFooter(View footer, LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper,
    boolean layoutInVertical, int parentWidth, int parentHeight, int parentHPadding, int parentVPadding) {
    if (footer == null) {
        return 0;
    }

    OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();

    final ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(
        footer.getLayoutParams());

    // fill width
    int widthSpec = helper.getChildMeasureSpec(parentWidth - parentHPadding,
        layoutInVertical ? MATCH_PARENT : lp.width, !layoutInVertical);
    int heightSpec = helper.getChildMeasureSpec(parentHeight - parentVPadding,
        layoutInVertical ? lp.height : MeasureSpec.EXACTLY, layoutInVertical);
    helper.measureChildWithMargins(footer, widthSpec, heightSpec);
    return orientationHelper.getDecoratedMeasurement(footer);
}
 
開發者ID:alibaba,項目名稱:vlayout,代碼行數:20,代碼來源:OnePlusNLayoutHelper.java

示例8: onMeasure

import android.view.View.MeasureSpec; //導入依賴的package包/類
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
	super.onMeasure(widthMeasureSpec, heightMeasureSpec);
	width = MeasureSpec.getSize(widthMeasureSpec);
	height = MeasureSpec.getSize(heightMeasureSpec);
	// Fit to screen.
	float scale;
	float scaleX = width / bmWidth;
	float scaleY = height / bmHeight;
	scale = Math.min(scaleX, scaleY);
	matrix.setScale(scale, scale);
	// minScale = scale;
	setImageMatrix(matrix);
	saveScale = 1f;

	// Center the image
	redundantYSpace = height - (scale * bmHeight);
	redundantXSpace = width - (scale * bmWidth);
	redundantYSpace /= (float) 2;
	redundantXSpace /= (float) 2;

	matrix.postTranslate(redundantXSpace, redundantYSpace);

	origWidth = width - 2 * redundantXSpace;
	origHeight = height - 2 * redundantYSpace;
	calcPadding();
	setImageMatrix(matrix);
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:29,代碼來源:TouchImageView.java

示例9: getRealWidth

import android.view.View.MeasureSpec; //導入依賴的package包/類
private int getRealWidth(int mode, int size) {
    int ret = size;
    if (View.MeasureSpec.AT_MOST == mode) {
        int childrenWidth = 0;
        Params p = (Params) mParams;

        childrenWidth = mPaddingLeft + mPaddingRight;
        int count = 0;
        for (ViewBase child : mSubViews) {
            childrenWidth += child.getComMeasuredWidthWithMargin();
            if (++count >= mColCount) {
                break;
            } else {
                childrenWidth += mItemHorizontalMargin;
            }
        }

        ret = Math.min(size, childrenWidth);
    } else if (View.MeasureSpec.EXACTLY == mode) {
        ret = size;
    } else {
        Log.e(TAG, "getRealWidth error mode:" + mode);
    }

    return ret;
}
 
開發者ID:alibaba,項目名稱:Virtualview-Android,代碼行數:27,代碼來源:GridLayout.java

示例10: loadBitmapFromView

import android.view.View.MeasureSpec; //導入依賴的package包/類
public static Bitmap loadBitmapFromView(View v) {
    if (v.getMeasuredHeight() > 0) {
        return null;
    }
    v.measure(MeasureSpec.makeMeasureSpec((int) DensityUtil.getScreenWidth(v.getContext()),
            1073741824), MeasureSpec.makeMeasureSpec(0, 0));
    Bitmap b = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Config
            .ARGB_8888);
    Canvas c = new Canvas(b);
    v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
    v.draw(c);
    return b;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:14,代碼來源:BitmapUtil.java

示例11: onMeasure

import android.view.View.MeasureSpec; //導入依賴的package包/類
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int height = MeasureSpec.getSize(heightMeasureSpec);

    if (width >= 2 * mIllustration.getWidth() && width > height) {
        mPromoContent.setOrientation(LinearLayout.HORIZONTAL);
        setMaxChildWidth(mMaxChildWidthHorizontal);
        ApiCompatibilityUtils.setPaddingRelative(
                mIllustration, 0, 0, mIllustrationPaddingSide, 0);
    } else {
        mPromoContent.setOrientation(LinearLayout.VERTICAL);
        setMaxChildWidth(mMaxChildWidth);
        mIllustration.setPadding(0, 0, 0, mIllustrationPaddingBottom);
    }

    setMaxChildHeight(height - mFrameHeightMargin);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:20,代碼來源:DataReductionPromoView.java

示例12: measureContentView

import android.view.View.MeasureSpec; //導入依賴的package包/類
private void measureContentView() {
    View rootView = mAnchorView.getRootView();
    getBackground().getPadding(mCachedPaddingRect);

    // The maximum width of the bubble is determined by how wide the root view is.
    int maxContentWidth =
            rootView.getWidth() - mCachedPaddingRect.left - mCachedPaddingRect.right;

    // The maximum height of the bubble is determined by the available space below the anchor.
    int anchorYOverlap = (int) -(mYOverlapPercentage * mAnchorView.getHeight());
    int maxContentHeight = getMaxAvailableHeight(mAnchorView, anchorYOverlap)
            - mCachedPaddingRect.top - mCachedPaddingRect.bottom;

    int contentWidthSpec = MeasureSpec.makeMeasureSpec(maxContentWidth, MeasureSpec.AT_MOST);
    int contentHeightSpec = MeasureSpec.makeMeasureSpec(maxContentHeight, MeasureSpec.AT_MOST);
    mContentView.measure(contentWidthSpec, contentHeightSpec);
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:18,代碼來源:TextBubble.java

示例13: onMeasure

import android.view.View.MeasureSpec; //導入依賴的package包/類
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    boolean textVisible = hasText();
    if (textVisible && this.mSavedPaddingLeft >= 0) {
        super.setPadding(this.mSavedPaddingLeft, getPaddingTop(), getPaddingRight(), getPaddingBottom());
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int oldMeasuredWidth = getMeasuredWidth();
    int targetWidth = widthMode == Integer.MIN_VALUE ? Math.min(widthSize, this.mMinWidth) : this.mMinWidth;
    if (widthMode != 1073741824 && this.mMinWidth > 0 && oldMeasuredWidth < targetWidth) {
        super.onMeasure(MeasureSpec.makeMeasureSpec(targetWidth, 1073741824), heightMeasureSpec);
    }
    if (!textVisible && this.mIcon != null) {
        super.setPadding((getMeasuredWidth() - this.mIcon.getBounds().width()) / 2, getPaddingTop(), getPaddingRight(), getPaddingBottom());
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:18,代碼來源:ActionMenuItemView.java

示例14: measureScrapChildWidth

import android.view.View.MeasureSpec; //導入依賴的package包/類
private void measureScrapChildWidth(View child, int position, int heightMeasureSpec) {
    int childWidthSpec;
    LayoutParams p = (LayoutParams) child.getLayoutParams();
    if (p == null) {
        p = (LayoutParams) generateDefaultLayoutParams();
        child.setLayoutParams(p);
    }
    p.viewType = this.mAdapter.getItemViewType(position);
    p.forceAdd = true;
    int childHeightSpec = ViewGroup.getChildMeasureSpec(heightMeasureSpec, this.mListPadding.top + this.mListPadding.bottom, p.height);
    int lpWidth = p.width;
    if (lpWidth > 0) {
        childWidthSpec = MeasureSpec.makeMeasureSpec(lpWidth, 1073741824);
    } else {
        childWidthSpec = MeasureSpec.makeMeasureSpec(0, 0);
    }
    child.measure(childWidthSpec, childHeightSpec);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:19,代碼來源:HListView.java

示例15: getChildMeasureSpec

import android.view.View.MeasureSpec; //導入依賴的package包/類
@Deprecated
public static int getChildMeasureSpec(int parentSize, int padding, int childDimension, boolean canScroll) {
    int size = Math.max(0, parentSize - padding);
    int resultSize = 0;
    int resultMode = 0;
    if (canScroll) {
        if (childDimension >= 0) {
            resultSize = childDimension;
            resultMode = 1073741824;
        } else {
            resultSize = 0;
            resultMode = 0;
        }
    } else if (childDimension >= 0) {
        resultSize = childDimension;
        resultMode = 1073741824;
    } else if (childDimension == -1) {
        resultSize = size;
        resultMode = 1073741824;
    } else if (childDimension == -2) {
        resultSize = size;
        resultMode = Integer.MIN_VALUE;
    }
    return MeasureSpec.makeMeasureSpec(resultSize, resultMode);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:26,代碼來源:RecyclerView.java


注:本文中的android.view.View.MeasureSpec類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。