Java Code Examples for android.view.View.MeasureSpec#makeMeasureSpec()

The following examples show how to use android.view.View.MeasureSpec#makeMeasureSpec() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectionPopupImpl.java    From IslamicLibraryAndroid with GNU General Public License v3.0 6 votes vote down vote up
private void layout() {
    int drawLocationY;
    int drawLocationX;
    int size;
    int width;
    int height;

    size = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    SelectionPopupImpl.this.mView.measure(size, size);
    height = SelectionPopupImpl.this.mView.getMeasuredHeight();
    width = SelectionPopupImpl.this.mView.getMeasuredWidth();
    drawLocationX = Math.min(SelectionPopupImpl.this.mScreenWidth - width, Math.max(0, (this.mSelectionLeft + ((this.mSelectionRight - this.mSelectionLeft) / 2)) - (width / 2)));
    drawLocationY = this.mSelectionTop - height >= 0 ? this.mSelectionTop - height : (this.mSelectionBottom + height) + this.mHandleLongerAxis >= SelectionPopupImpl.this.mScreenHeight ? this.mHandleLongerAxis > 0 ? this.mSelectionBottom - height : ((this.mSelectionBottom + this.mSelectionTop) / 2) - (height / 2) : this.mSelectionBottom + this.mHandleLongerAxis;

    LayoutParams layoutParams = (LayoutParams) SelectionPopupImpl.this.mView.getLayoutParams();
    layoutParams.leftMargin = drawLocationX;
    layoutParams.topMargin = drawLocationY;
    layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    SelectionPopupImpl.this.mView.requestLayout();
}
 
Example 2
Source File: WidgetUtils.java    From SprintNBA with Apache License 2.0 6 votes vote down vote up
/**
 * 测量控件
 *
 * @param view
 */
public static void measureView(View view) {
    ViewGroup.LayoutParams p = view.getLayoutParams();
    if (p == null) {
        p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
    }
    int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0 + 0, p.width);
    int lpHeight = p.height;
    int childHeightSpec;
    if (lpHeight > 0) {
        childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight,
                MeasureSpec.EXACTLY);
    } else {
        childHeightSpec = MeasureSpec.makeMeasureSpec(0,
                MeasureSpec.UNSPECIFIED);
    }
    view.measure(childWidthSpec, childHeightSpec);
}
 
Example 3
Source File: IcsListPopupWindow.java    From android-apps with MIT License 6 votes vote down vote up
private void measureScrapChild(View child, int position, int widthMeasureSpec) {
    ListView.LayoutParams p = (ListView.LayoutParams) child.getLayoutParams();
    if (p == null) {
        p = new ListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 0);
        child.setLayoutParams(p);
    }
    //XXX p.viewType = mAdapter.getItemViewType(position);
    //XXX p.forceAdd = true;

    int childWidthSpec = ViewGroup.getChildMeasureSpec(widthMeasureSpec,
            mDropDownList.getPaddingLeft() + mDropDownList.getPaddingRight(), p.width);
    int lpHeight = p.height;
    int childHeightSpec;
    if (lpHeight > 0) {
        childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY);
    } else {
        childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    }
    child.measure(childWidthSpec, childHeightSpec);
}
 
Example 4
Source File: IcsListPopupWindow.java    From Libraries-for-Android-Developers with MIT License 6 votes vote down vote up
private void measureScrapChild(View child, int position, int widthMeasureSpec) {
    ListView.LayoutParams p = (ListView.LayoutParams) child.getLayoutParams();
    if (p == null) {
        p = new ListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 0);
        child.setLayoutParams(p);
    }
    //XXX p.viewType = mAdapter.getItemViewType(position);
    //XXX p.forceAdd = true;

    int childWidthSpec = ViewGroup.getChildMeasureSpec(widthMeasureSpec,
            mDropDownList.getPaddingLeft() + mDropDownList.getPaddingRight(), p.width);
    int lpHeight = p.height;
    int childHeightSpec;
    if (lpHeight > 0) {
        childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY);
    } else {
        childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    }
    child.measure(childWidthSpec, childHeightSpec);
}
 
Example 5
Source File: FabTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private FloatingActionButton createFabForTest(boolean ensureMinTouchTarget) {
  FloatingActionButton fab = new FloatingActionButton(activity);
  float dimen = dpToPx(activity, MIN_SIZE_FOR_ALLY_DP);
  fab.setSize(SIZE_MINI);
  fab.setEnsureMinTouchTargetSize(ensureMinTouchTarget);
  int measureSpec = MeasureSpec.makeMeasureSpec((int) (dimen * 2), MeasureSpec.AT_MOST);
  fab.measure(measureSpec, measureSpec);
  return fab;
}
 
Example 6
Source File: SquareFrameLayout.java    From CameraV with GNU General Public License v3.0 6 votes vote down vote up
@Override 
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
 
	if (MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.UNSPECIFIED)
	{
		int inhibitedHeightSpec = MeasureSpec.makeMeasureSpec((int) (MeasureSpec.getSize(widthMeasureSpec)),
				MeasureSpec.getMode(widthMeasureSpec));
		super.onMeasure(widthMeasureSpec, inhibitedHeightSpec);
	}
	else
	{
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		int width = this.getMeasuredWidth();
			int height = (int) (width);
			super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
	}
}
 
Example 7
Source File: AbViewUtil.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public static int getAbsListViewHeight(AbsListView absListView, int lineNumber, int verticalSpace) {
    int totalHeight = 0;
    int w = MeasureSpec.makeMeasureSpec(0, 0);
    int h = MeasureSpec.makeMeasureSpec(0, 0);
    absListView.measure(w, h);
    ListAdapter mListAdapter = (ListAdapter) absListView.getAdapter();
    if (mListAdapter == null) {
        return 0;
    }
    int count = mListAdapter.getCount();
    View listItem;
    if (absListView instanceof ListView) {
        for (int i = 0; i < count; i++) {
            listItem = mListAdapter.getView(i, null, absListView);
            listItem.measure(w, h);
            totalHeight += listItem.getMeasuredHeight();
        }
        if (count == 0) {
            totalHeight = verticalSpace;
        } else {
            totalHeight += ((ListView) absListView).getDividerHeight() * (count - 1);
        }
    } else if (absListView instanceof GridView) {
        int remain = count % lineNumber;
        if (remain > 0) {
            remain = 1;
        }
        if (mListAdapter.getCount() == 0) {
            totalHeight = verticalSpace;
        } else {
            listItem = mListAdapter.getView(0, null, absListView);
            listItem.measure(w, h);
            int line = (count / lineNumber) + remain;
            totalHeight = (listItem.getMeasuredHeight() * line) + ((line - 1) * verticalSpace);
        }
    }
    return totalHeight;
}
 
Example 8
Source File: ActionMenuPresenter.java    From zhangshangwuda with Apache License 2.0 5 votes vote down vote up
@Override
public void initForMenu(Context context, MenuBuilder menu) {
    super.initForMenu(context, menu);

    final Resources res = context.getResources();

    if (!mReserveOverflowSet) {
        mReserveOverflow = reserveOverflow(mContext);
    }

    if (!mWidthLimitSet) {
        mWidthLimit = res.getDisplayMetrics().widthPixels / 2;
    }

    // Measure for initial configuration
    if (!mMaxItemsSet) {
        mMaxItems = getResources_getInteger(context, R.integer.abs__max_action_buttons);
    }

    int width = mWidthLimit;
    if (mReserveOverflow) {
        if (mOverflowButton == null) {
            mOverflowButton = new OverflowMenuButton(mSystemContext);
            final int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
            mOverflowButton.measure(spec, spec);
        }
        width -= mOverflowButton.getMeasuredWidth();
    } else {
        mOverflowButton = null;
    }

    mActionItemWidthLimit = width;

    mMinCellSize = (int) (ActionMenuView.MIN_CELL_SIZE * res.getDisplayMetrics().density);

    // Drop a scrap view as it may no longer reflect the proper context/config.
    mScrapActionButtonView = null;
}
 
Example 9
Source File: NoAnimationLayoutAnimator.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void animateChanges(LayoutChangeset changes,
		FreeFlowContainer callback) {
	this.changes = changes;
	for(Pair<FreeFlowItem, Rect> item : changes.getMoved()){
		Rect r = item.first.frame;
		View v = item.first.view;
		int wms = MeasureSpec.makeMeasureSpec(r.right-r.left, MeasureSpec.EXACTLY);
		int hms = MeasureSpec.makeMeasureSpec(r.bottom-r.top, MeasureSpec.EXACTLY);
		v.measure(wms,hms );
		v.layout(r.left, r.top, r.right, r.bottom);	
	}
	callback.onLayoutChangeAnimationsCompleted(this);
	
}
 
Example 10
Source File: KPSwitchPanelLayoutHandler.java    From letv with Apache License 2.0 5 votes vote down vote up
public int[] processOnMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (this.mIsHide) {
        this.panelLayout.setVisibility(8);
        widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, 1073741824);
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, 1073741824);
    }
    this.processedMeasureWHSpec[0] = widthMeasureSpec;
    this.processedMeasureWHSpec[1] = heightMeasureSpec;
    return this.processedMeasureWHSpec;
}
 
Example 11
Source File: CustomDrawerLayout.java    From FidoCadJ with GNU General Public License v3.0 5 votes vote down vote up
/** Called when  a measurement operation is done.
    @param widthMeasureSpec the wanted with.
    @param heightMeasureSpec the wanted height.
*/
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
    widthMeasureSpec = MeasureSpec.makeMeasureSpec(
            MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY);
    heightMeasureSpec = MeasureSpec.makeMeasureSpec(
            MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.EXACTLY);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
 
Example 12
Source File: SwitchButton.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);
    Resources r = Resources.getSystem();
    if (widthMode == 0 || widthMode == Integer.MIN_VALUE) {
        widthMeasureSpec = MeasureSpec.makeMeasureSpec((int) TypedValue.applyDimension(1, 50.0f, r.getDisplayMetrics()), NTLMConstants.FLAG_NEGOTIATE_KEY_EXCHANGE);
    }
    if (heightSize == 0 || heightSize == Integer.MIN_VALUE) {
        heightMeasureSpec = MeasureSpec.makeMeasureSpec((int) TypedValue.applyDimension(1, 30.0f, r.getDisplayMetrics()), NTLMConstants.FLAG_NEGOTIATE_KEY_EXCHANGE);
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
 
Example 13
Source File: PagerTitleStrip.java    From letv with Apache License 2.0 5 votes vote down vote up
void updateText(int currentItem, PagerAdapter adapter) {
    int itemCount;
    if (adapter != null) {
        itemCount = adapter.getCount();
    } else {
        itemCount = 0;
    }
    this.mUpdatingText = true;
    CharSequence text = null;
    if (currentItem >= 1 && adapter != null) {
        text = adapter.getPageTitle(currentItem - 1);
    }
    this.mPrevText.setText(text);
    TextView textView = this.mCurrText;
    CharSequence pageTitle = (adapter == null || currentItem >= itemCount) ? null : adapter.getPageTitle(currentItem);
    textView.setText(pageTitle);
    text = null;
    if (currentItem + 1 < itemCount && adapter != null) {
        text = adapter.getPageTitle(currentItem + 1);
    }
    this.mNextText.setText(text);
    int childWidthSpec = MeasureSpec.makeMeasureSpec(Math.max(0, (int) (((float) ((getWidth() - getPaddingLeft()) - getPaddingRight())) * 0.8f)), Integer.MIN_VALUE);
    int childHeightSpec = MeasureSpec.makeMeasureSpec(Math.max(0, (getHeight() - getPaddingTop()) - getPaddingBottom()), Integer.MIN_VALUE);
    this.mPrevText.measure(childWidthSpec, childHeightSpec);
    this.mCurrText.measure(childWidthSpec, childHeightSpec);
    this.mNextText.measure(childWidthSpec, childHeightSpec);
    this.mLastKnownCurrentPage = currentItem;
    if (!this.mUpdatingPositions) {
        updateTextPositions(currentItem, this.mLastKnownPositionOffset, false);
    }
    this.mUpdatingText = false;
}
 
Example 14
Source File: EditorActivity.java    From APDE with GNU General Public License v2.0 5 votes vote down vote up
private static int getTextViewHeight(Context context, String text, float textSize, int deviceWidth, int padding) {
	TextView textView = new TextView(context);
	textView.setText(text);
	textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
	textView.setPadding(padding, padding, padding, padding);
	
	int widthMeasureSpec = MeasureSpec.makeMeasureSpec(deviceWidth, MeasureSpec.AT_MOST);
	int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
	
	textView.measure(widthMeasureSpec, heightMeasureSpec);
	return textView.getMeasuredHeight();
}
 
Example 15
Source File: FloatingToolbar.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int height = mPopup.mOverflowPanelSize.getHeight() - mPopup.mOverflowButtonSize.getHeight();
    heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
 
Example 16
Source File: ChipTest.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
private void setupAndMeasureChip(boolean shouldEnsureMinTouchTargeSize) {
  chip.setEnsureMinTouchTargetSize(shouldEnsureMinTouchTargeSize);
  int measureSpec =
      MeasureSpec.makeMeasureSpec((int) (getMinTouchTargetSize() * 2), MeasureSpec.AT_MOST);
  chip.measure(measureSpec, measureSpec);
}
 
Example 17
Source File: FadingActionBarHelperBase.java    From ALLGO with Apache License 2.0 4 votes vote down vote up
public final View createView(LayoutInflater inflater) {
    //
    // Prepare everything

    mInflater = inflater;
    if (mContentView == null) {
        mContentView = inflater.inflate(mContentLayoutResId, null);
    }
    if (mHeaderView == null) {
        mHeaderView = inflater.inflate(mHeaderLayoutResId, null, false);
    }

    //
    // See if we are in a ListView or ScrollView scenario

    ListView listView = (ListView) mContentView.findViewById(android.R.id.list);
    View root;
    if (listView != null) {
        root = createListView(listView);
    } else {
        root = createScrollView();
    }

    if (mHeaderOverlayView == null && mHeaderOverlayLayoutResId != 0) {
        mHeaderOverlayView = inflater.inflate(mHeaderOverlayLayoutResId, mMarginView, false);
    }
    if (mHeaderOverlayView != null) {
        mMarginView.addView(mHeaderOverlayView);
    }

    // Use measured height here as an estimate of the header height, later on after the layout is complete 
    // we'll use the actual height
    int widthMeasureSpec = MeasureSpec.makeMeasureSpec(LayoutParams.MATCH_PARENT, MeasureSpec.EXACTLY);
    int heightMeasureSpec = MeasureSpec.makeMeasureSpec(LayoutParams.WRAP_CONTENT, MeasureSpec.EXACTLY);
    mHeaderView.measure(widthMeasureSpec, heightMeasureSpec);
    updateHeaderHeight(mHeaderView.getMeasuredHeight());

    root.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            int headerHeight = mHeaderContainer.getHeight();
            if (!mFirstGlobalLayoutPerformed && headerHeight != 0) {
                updateHeaderHeight(headerHeight);
                mFirstGlobalLayoutPerformed = true;
            }
        }
    });
    return root;
}
 
Example 18
Source File: FadingActionBarHelperBase.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
public final View createView(LayoutInflater inflater) {
    //
    // Prepare everything

    mInflater = inflater;
    if (mContentView == null) {
        mContentView = inflater.inflate(mContentLayoutResId, null);
    }
    if (mHeaderView == null) {
        mHeaderView = inflater.inflate(mHeaderLayoutResId, null, false);
    }

    //
    // See if we are in a ListView, WebView or ScrollView scenario

    ListView listView = (ListView) mContentView.findViewById(android.R.id.list);
    View root;
    if (listView != null) {
        root = createListView(listView);
    } else if (mContentView instanceof ObservableWebViewWithHeader){
        root = createWebView();
    } else {
        root = createScrollView();
    }

    if (mHeaderOverlayView == null && mHeaderOverlayLayoutResId != 0) {
        mHeaderOverlayView = inflater.inflate(mHeaderOverlayLayoutResId, mMarginView, false);
    }
    if (mHeaderOverlayView != null) {
        mMarginView.addView(mHeaderOverlayView);
    }

    // Use measured height here as an estimate of the header height, later on after the layout is complete 
    // we'll use the actual height
    int widthMeasureSpec = MeasureSpec.makeMeasureSpec(LayoutParams.MATCH_PARENT, MeasureSpec.EXACTLY);
    int heightMeasureSpec = MeasureSpec.makeMeasureSpec(LayoutParams.WRAP_CONTENT, MeasureSpec.EXACTLY);
    mHeaderView.measure(widthMeasureSpec, heightMeasureSpec);
    updateHeaderHeight(mHeaderView.getMeasuredHeight());

    root.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            int headerHeight = mHeaderContainer.getHeight();
            if (!mFirstGlobalLayoutPerformed && headerHeight != 0) {
                updateHeaderHeight(headerHeight);
                mFirstGlobalLayoutPerformed = true;
            }
        }
    });
    return root;
}
 
Example 19
Source File: FloatingToolbar.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int height = mPopup.mOverflowPanelSize.getHeight() - mPopup.mOverflowButtonSize.getHeight();
    heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
 
Example 20
Source File: RecyclerViewItemRelayout.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), (int) (((float) getDefaultSize(0, widthMeasureSpec)) * 0.75f));
    super.onMeasure(MeasureSpec.makeMeasureSpec(getMeasuredWidth(), NTLMConstants.FLAG_NEGOTIATE_KEY_EXCHANGE), MeasureSpec.makeMeasureSpec(getMeasuredHeight(), NTLMConstants.FLAG_NEGOTIATE_KEY_EXCHANGE));
}