List of usage examples for android.view View measure
public final void measure(int widthMeasureSpec, int heightMeasureSpec)
This is called to find out how big a view should be.
From source file:com.duy.pascal.ui.debug.activities.DebugActivity.java
@WorkerThread private void showPopupAt(final LineNumber lineNumber, final String msg) { mHandler.post(new Runnable() { @Override/* www . java 2 s. c o m*/ public void run() { if (isFinishing()) return; //get relative position of expression at edittext Point position = mCodeView.getDebugPosition(lineNumber.getLine(), lineNumber.getColumn(), Gravity.TOP); DLog.d(TAG, "generate: " + position); dismissPopup(); //create new popup PopupWindow window = new PopupWindow(DebugActivity.this); LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View container = inflater.inflate(R.layout.popup_expr_result, null); container.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); int windowHeight = container.getMeasuredHeight(); int windowWidth = container.getMeasuredWidth(); window.setContentView(container); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); window.setTouchable(true); window.setSplitTouchEnabled(true); window.setOutsideTouchable(true); window.showAtLocation(mCodeView, Gravity.NO_GRAVITY, position.x - windowWidth / 3, position.y + toolbar.getHeight() - windowHeight); TextView txtResult = container.findViewById(R.id.txt_result); txtResult.setText(msg); AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.5f); alphaAnimation.setDuration(1000); alphaAnimation.setRepeatMode(Animation.REVERSE); alphaAnimation.setRepeatCount(Animation.INFINITE); txtResult.startAnimation(alphaAnimation); DebugActivity.this.mPopupWindow = window; } }); }
From source file:com.bamalearn.bamalearnburmese.DrawerMainActivity.java
public void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { return;//from w w w . j a v a2s . co m } int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom(); for (int i = 0; i < listAdapter.getCount(); i++) { View listItem = listAdapter.getView(i, null, listView); if (listItem instanceof ViewGroup) listItem.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.WRAP_CONTENT, AbsListView.LayoutParams.WRAP_CONTENT)); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); }
From source file:com.astuetz.viewpager.extensions.SwipeyTabsView.java
/** * {@inheritDoc}/*from w w w. j ava 2 s. co m*/ */ @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int maxTabHeight = 0; mWidthMeasureSpec = widthMeasureSpec; mHeightMeasureSpec = heightMeasureSpec; final int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.AT_MOST); final int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.AT_MOST); for (int i = 0; i < mTabsCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) continue; child.measure(childWidthMeasureSpec, childHeightMeasureSpec); mPositions.get(i).width = child.getMeasuredWidth(); mPositions.get(i).height = child.getMeasuredHeight(); maxTabHeight = Math.max(maxTabHeight, mPositions.get(i).height); } setMeasuredDimension(resolveSize(0, widthMeasureSpec), resolveSize(maxTabHeight + getPaddingTop() + getPaddingBottom(), heightMeasureSpec)); }
From source file:com.asc_ii.bangnote.bigbang.BigBangLayout.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int widthSize = MeasureSpec.getSize(widthMeasureSpec) - getPaddingLeft() - getPaddingRight(); int contentWidthSize = widthSize - mActionBar.getContentPadding(); int heightSize = 0; int childCount = getChildCount(); int measureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); mLines = new ArrayList<>(); Line currentLine = null;//from w ww.ja v a2 s. c o m int currentLineWidth = contentWidthSize; for (int i = 0; i < childCount; i++) { View child = getChildAt(i); if (mActionBar == child) { continue; } child.measure(measureSpec, measureSpec); if (currentLineWidth > 0) { currentLineWidth += mItemSpace; } currentLineWidth += child.getMeasuredWidth(); if (mLines.size() == 0 || currentLineWidth > contentWidthSize) { heightSize += child.getMeasuredHeight(); currentLineWidth = child.getMeasuredWidth(); currentLine = new Line(mLines.size()); mLines.add(currentLine); } Item item = new Item(currentLine); item.view = child; item.index = i; item.width = child.getMeasuredWidth(); item.height = child.getMeasuredHeight(); currentLine.addItem(item); } Line firstSelectedLine = findFirstSelectedLine(); Line lastSelectedLine = findLastSelectedLine(); if (firstSelectedLine != null && lastSelectedLine != null) { int selectedLineHeight = (lastSelectedLine.index - firstSelectedLine.index + 1) * (firstSelectedLine.getHeight() + mLineSpace); mActionBar.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(selectedLineHeight, MeasureSpec.UNSPECIFIED)); } int size = heightSize + getPaddingTop() + getPaddingBottom() + (mLines.size() - 1) * mLineSpace + mActionBarTopHeight + mActionBarBottomHeight; super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY)); }
From source file:com.cqyw.goheadlines.widget.horizonListView.HorizontalListView.java
private void addAndMeasureChild(final View child, int viewPos) { LayoutParams params = child.getLayoutParams(); if (params == null) { params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); }//from w w w . j av a2 s . co m addViewInLayout(child, viewPos, params, true); child.measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.AT_MOST)); }
From source file:com.android.mail.browse.ConversationItemView.java
private static void layoutViewExactly(View v, int w, int h) { v.measure(makeExactSpecForSize(w), makeExactSpecForSize(h)); v.layout(0, 0, w, h);/* www. ja v a2 s .com*/ }
From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java
public SuggestionStripLayoutHelper(final Context context, final AttributeSet attrs, final int defStyle, final ArrayList<TextView> wordViews, final ArrayList<View> dividerViews, final ArrayList<TextView> debugInfoViews) { mWordViews = wordViews;/* w ww . ja v a 2 s .c o m*/ mDividerViews = dividerViews; mDebugInfoViews = debugInfoViews; final TextView wordView = wordViews.get(0); final View dividerView = dividerViews.get(0); mPadding = wordView.getCompoundPaddingLeft() + wordView.getCompoundPaddingRight(); dividerView.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); mDividerWidth = dividerView.getMeasuredWidth(); final Resources res = wordView.getResources(); mSuggestionsStripHeight = res.getDimensionPixelSize(R.dimen.config_suggestions_strip_height); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SuggestionStripView, defStyle, R.style.SuggestionStripView); mSuggestionStripOptions = a.getInt(R.styleable.SuggestionStripView_suggestionStripOptions, 0); mAlphaObsoleted = ResourceUtils.getFraction(a, R.styleable.SuggestionStripView_alphaObsoleted, 1.0f); mColorValidTypedWord = a.getColor(R.styleable.SuggestionStripView_colorValidTypedWord, 0); mColorTypedWord = a.getColor(R.styleable.SuggestionStripView_colorTypedWord, 0); mColorAutoCorrect = a.getColor(R.styleable.SuggestionStripView_colorAutoCorrect, 0); mColorSuggested = a.getColor(R.styleable.SuggestionStripView_colorSuggested, 0); mSuggestionsCountInStrip = a.getInt(R.styleable.SuggestionStripView_suggestionsCountInStrip, DEFAULT_SUGGESTIONS_COUNT_IN_STRIP); mCenterSuggestionWeight = ResourceUtils.getFraction(a, R.styleable.SuggestionStripView_centerSuggestionPercentile, DEFAULT_CENTER_SUGGESTION_PERCENTILE); mMaxMoreSuggestionsRow = a.getInt(R.styleable.SuggestionStripView_maxMoreSuggestionsRow, DEFAULT_MAX_MORE_SUGGESTIONS_ROW); mMinMoreSuggestionsWidth = ResourceUtils.getFraction(a, R.styleable.SuggestionStripView_minMoreSuggestionsWidth, 1.0f); a.recycle(); mMoreSuggestionsHint = getMoreSuggestionsHint(res, res.getDimension(R.dimen.config_more_suggestions_hint_text_size), mColorAutoCorrect); mCenterPositionInStrip = mSuggestionsCountInStrip / 2; // Assuming there are at least three suggestions. Also, note that the suggestions are // laid out according to script direction, so this is left of the center for LTR scripts // and right of the center for RTL scripts. mTypedWordPositionWhenAutocorrect = mCenterPositionInStrip - 1; mMoreSuggestionsBottomGap = res.getDimensionPixelOffset(R.dimen.config_more_suggestions_bottom_gap); mMoreSuggestionsRowHeight = res.getDimensionPixelSize(R.dimen.config_more_suggestions_row_height); }
From source file:com.dvn.vindecoder.ui.seller.AddVehicalAndPayment.java
public void setViewPagerHeight() { viewPager = new ViewPager(AddVehicalAndPayment.this) { @Override//w w w . j ava 2s . c o m protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); View view = getChildAt(this.getCurrentItem()); if (view != null) { view.measure(widthMeasureSpec, heightMeasureSpec); } setMeasuredDimension(getMeasuredWidth(), measureHeight(heightMeasureSpec, view)); } private int measureHeight(int measureSpec, View view) { int result = 0; int specMode = MeasureSpec.getMode(measureSpec); int specSize = MeasureSpec.getSize(measureSpec); if (specMode == MeasureSpec.EXACTLY) { result = specSize; } else { // set the height from the base view if available if (view != null) { result = view.getMeasuredHeight(); } if (specMode == MeasureSpec.AT_MOST) { result = Math.min(result, specSize); } } return result; } }; }
From source file:com.facebook.litho.ViewCompatComponent.java
@Override protected void onMeasure(ComponentContext c, ComponentLayout layout, int widthSpec, int heightSpec, Size size, Component<?> component) { final ViewCompatComponentImpl impl = (ViewCompatComponentImpl) component; final ViewBinder viewBinder = impl.mViewBinder; final boolean isSafeToAllocatePool = getValidActivityForContext(c) != null; View toMeasure = (View) ComponentsPools.acquireMountContent(c, getId(), isSafeToAllocatePool); if (toMeasure == null) { toMeasure = mViewCompatCreator.createView(c); }/*from w ww .j a v a 2 s.co m*/ ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(size.width, size.height); toMeasure.setLayoutParams(layoutParams); viewBinder.bind(toMeasure); if (toMeasure.getVisibility() == View.GONE) { // No need to measure the view if binding it caused its visibility to become GONE. size.width = 0; size.height = 0; } else { toMeasure.measure(widthSpec, heightSpec); size.width = toMeasure.getMeasuredWidth(); size.height = toMeasure.getMeasuredHeight(); } viewBinder.unbind(toMeasure); ComponentsPools.release(c, this, toMeasure); }
From source file:com.example.igorklimov.popularmoviesdemo.fragments.DetailFragment.java
private void setListViewHeight(ExpandableListView listView, int group) { ExpandableListAdapter listAdapter = listView.getExpandableListAdapter(); if (mDefaultHeight == 0) mDefaultHeight = listView.getHeight(); int totalHeight = 0; int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.EXACTLY); for (int i = 0; i < listAdapter.getGroupCount(); i++) { if (((listView.isGroupExpanded(i)) && (i != group)) || ((!listView.isGroupExpanded(i)) && (i == group))) { for (int j = 0; j < listAdapter.getChildrenCount(i); j++) { View listItem = listAdapter.getChildView(i, j, false, null, listView); listItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED); totalHeight += listItem.getMeasuredHeight(); }/*from ww w .ja v a2 s.c o m*/ totalHeight += mDefaultHeight; } } ViewGroup.LayoutParams params = listView.getLayoutParams(); int height = totalHeight + (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1)); if (height < mDefaultHeight) height = mDefaultHeight; params.height = height; listView.setLayoutParams(params); listView.requestLayout(); }