List of usage examples for android.view View getMeasuredHeight
public final int getMeasuredHeight()
From source file:com.appeaser.sublimepickerlibrary.datepicker.DayPickerViewPager.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { //populate(); // Use reflection callPopulate();//from ww w.ja v a 2 s. c o m // Everything below is mostly copied from FrameLayout. int count = getChildCount(); final boolean measureMatchParentChildren = MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY || MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY; int maxHeight = 0; int maxWidth = 0; int childState = 0; for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { measureChild(child, widthMeasureSpec, heightMeasureSpec); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); maxWidth = Math.max(maxWidth, child.getMeasuredWidth()); maxHeight = Math.max(maxHeight, child.getMeasuredHeight()); childState = combineMeasuredStates(childState, child.getMeasuredState()); if (measureMatchParentChildren) { if (lp.width == LayoutParams.MATCH_PARENT || lp.height == LayoutParams.MATCH_PARENT) { mMatchParentChildren.add(child); } } } } // Account for padding too maxWidth += getPaddingLeft() + getPaddingRight(); maxHeight += getPaddingTop() + getPaddingBottom(); // Check against our minimum height and width maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight()); maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth()); // Check against our foreground's minimum height and width if (SUtils.isApi_23_OrHigher()) { final Drawable drawable = getForeground(); if (drawable != null) { maxHeight = Math.max(maxHeight, drawable.getMinimumHeight()); maxWidth = Math.max(maxWidth, drawable.getMinimumWidth()); } } setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState), resolveSizeAndState(maxHeight, heightMeasureSpec, childState << MEASURED_HEIGHT_STATE_SHIFT)); count = mMatchParentChildren.size(); if (count > 1) { for (int i = 0; i < count; i++) { final View child = mMatchParentChildren.get(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int childWidthMeasureSpec; final int childHeightMeasureSpec; if (lp.width == LayoutParams.MATCH_PARENT) { childWidthMeasureSpec = MeasureSpec.makeMeasureSpec( getMeasuredWidth() - getPaddingLeft() - getPaddingRight(), MeasureSpec.EXACTLY); } else { childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, getPaddingLeft() + getPaddingRight(), lp.width); } if (lp.height == LayoutParams.MATCH_PARENT) { childHeightMeasureSpec = MeasureSpec.makeMeasureSpec( getMeasuredHeight() - getPaddingTop() - getPaddingBottom(), MeasureSpec.EXACTLY); } else { childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec, getPaddingTop() + getPaddingBottom(), lp.height); } child.measure(childWidthMeasureSpec, childHeightMeasureSpec); } } mMatchParentChildren.clear(); }
From source file:br.ufrgs.ufrgsmapas.libs.SearchBox.java
/** * Get the bar height/*w w w . j a va 2 s . c o m*/ * @return Height in Px */ public int getBarHeightPx() { View card = findViewById(R.id.card_view); card.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); int height = card.getMeasuredHeight(); return height; }
From source file:com.android.calculator2.CalculatorPadLayout.java
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { final int paddingLeft = getPaddingLeft(); final int paddingRight = getPaddingRight(); final int paddingTop = getPaddingTop(); final int paddingBottom = getPaddingBottom(); final boolean isRTL = ViewCompat.getLayoutDirection(this) == LAYOUT_DIRECTION_RTL; final int columnWidth = Math.round((float) (right - left - paddingLeft - paddingRight)) / mColumnCount; final int rowHeight = Math.round((float) (bottom - top - paddingTop - paddingBottom)) / mRowCount; int rowIndex = 0, columnIndex = 0; for (int childIndex = 0; childIndex < getChildCount(); ++childIndex) { final View childView = getChildAt(childIndex); if (childView.getVisibility() == View.GONE) { continue; }/*from w w w.ja v a 2 s . com*/ final MarginLayoutParams lp = (MarginLayoutParams) childView.getLayoutParams(); final int childTop = paddingTop + lp.topMargin + rowIndex * rowHeight; final int childBottom = childTop - lp.topMargin - lp.bottomMargin + rowHeight; final int childLeft = paddingLeft + lp.leftMargin + (isRTL ? (mColumnCount - 1) - columnIndex : columnIndex) * columnWidth; final int childRight = childLeft - lp.leftMargin - lp.rightMargin + columnWidth; final int childWidth = childRight - childLeft; final int childHeight = childBottom - childTop; if (childWidth != childView.getMeasuredWidth() || childHeight != childView.getMeasuredHeight()) { childView.measure(MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.EXACTLY)); } childView.layout(childLeft, childTop, childRight, childBottom); rowIndex = (rowIndex + (columnIndex + 1) / mColumnCount) % mRowCount; columnIndex = (columnIndex + 1) % mColumnCount; } }
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 w w. ja va2 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:ca.barrenechea.widget.recyclerview.decoration.DoubleHeaderDecoration.java
private void measureView(RecyclerView parent, View header) { int widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY); int heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.UNSPECIFIED); int childWidth = ViewGroup.getChildMeasureSpec(widthSpec, parent.getPaddingLeft() + parent.getPaddingRight(), header.getLayoutParams().width); int childHeight = ViewGroup.getChildMeasureSpec(heightSpec, parent.getPaddingTop() + parent.getPaddingBottom(), header.getLayoutParams().height); header.measure(childWidth, childHeight); header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight()); }
From source file:android.support.v7ox.widget.ActionBarOverlayLayout.java
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { final int count = getChildCount(); final int parentLeft = getPaddingLeft(); final int parentRight = right - left - getPaddingRight(); final int parentTop = getPaddingTop(); final int parentBottom = bottom - top - getPaddingBottom(); for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int width = child.getMeasuredWidth(); final int height = child.getMeasuredHeight(); int childLeft = parentLeft + lp.leftMargin; int childTop = parentTop + lp.topMargin; child.layout(childLeft, childTop, childLeft + width, childTop + height); }//from w w w. jav a2 s.c o m } }
From source file:com.lgallardo.qbittorrentclient.TorrentDetailsFragment.java
/** * *//from w w w.j ava2 s. c o m * Method for Setting the Height of the ListView dynamically. Hack to fix * the issue of not showing all the items of the ListView when placed inside * a ScrollView * ** */ public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) return; int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.UNSPECIFIED); int totalHeight = 0; View view = null; for (int i = 0; i < listAdapter.getCount(); i++) { long numOfLines = 1; view = listAdapter.getView(i, view, listView); if (i == 0) { view.setLayoutParams(new LayoutParams(desiredWidth, LayoutParams.WRAP_CONTENT)); } view.measure(desiredWidth, MeasureSpec.UNSPECIFIED); TextView file = (TextView) view.findViewById(R.id.file); TextView percentage = (TextView) view.findViewById(R.id.percentage); ProgressBar progressBar1 = (ProgressBar) view.findViewById(R.id.progressBar1); if (view.getMeasuredWidth() > desiredWidth) { double viewWidthLong = Double.valueOf(view.getMeasuredWidth()); double desiredWidthLong = Double.valueOf(desiredWidth); numOfLines = Math.round(viewWidthLong / desiredWidthLong) + 1; totalHeight += (file.getMeasuredHeight() * numOfLines) + percentage.getMeasuredHeight() + progressBar1.getMeasuredHeight(); } else { totalHeight += view.getMeasuredHeight(); } } LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); listView.requestLayout(); }
From source file:com.coco.slidinguppanel.SlidingUpPanel.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { if (getChildCount() > 1) { throw new IllegalStateException("SlidingUpPanel can only contain on child view"); } else if (getChildCount() == 1) { final View child = getChildAt(0); if (child.getVisibility() != GONE) { final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); final int width = child.getMeasuredWidth(); final int height = child.getMeasuredHeight(); final int left = getPaddingLeft() + lp.leftMargin; final int top = getPaddingTop() + lp.topMargin; child.layout(left, top, left + width, top + height); if (mIsOpen) { scrollTo(0, height);/*w ww .j ava 2 s . c o m*/ mIsOpen = false; openPanel(); } } } }
From source file:com.android2ee.recyclerview.itemanimator.PendingItemAnimator.java
void reset(View v) { ViewCompat.setAlpha(v, 1);// w ww .ja v a2 s . com ViewCompat.setScaleY(v, 1); ViewCompat.setScaleX(v, 1); ViewCompat.setTranslationY(v, 0); ViewCompat.setTranslationX(v, 0); ViewCompat.setRotation(v, 0); ViewCompat.setRotationY(v, 0); ViewCompat.setRotationX(v, 0); v.setPivotX(v.getMeasuredWidth() / 2); v.setPivotY(v.getMeasuredHeight() / 2); ViewCompat.animate(v).setInterpolator(null); }
From source file:com.cw.litenote.operation.audio.AudioPlayer_page.java
/** * Scroll highlight audio item to visible position * * At the following conditions/*w w w .j av a 2 s . c o m*/ * 1) click audio item of list view (this highlight is not good for user expectation, so cancel this condition now) * 2) click previous/next item in audio controller * 3) change tab to playing tab * 4) back from key protect off * 5) if seeker bar reaches the end * In order to view audio highlight item, playing(highlighted) audio item can be auto scrolled to top, * unless it is at the end page of list view, there is no need to scroll. */ public void scrollHighlightAudioItemToVisible(RecyclerView recyclerView) { // System.out.println("AudioPlayer_page / _scrollHighlightAudioItemToVisible"); if (recyclerView == null) return; LinearLayoutManager layoutMgr = ((LinearLayoutManager) recyclerView.getLayoutManager()); // version limitation: _scrollListBy // NoteFragment.drag_listView.scrollListBy(firstVisibleIndex_top); if (Build.VERSION.SDK_INT < 19) return; int pos; int itemHeight = 50;//init int dividerHeight; int firstVisible_note_pos; View v; pos = layoutMgr.findFirstVisibleItemPosition(); // System.out.println("---------------- pos = " + pos); View childView; if (recyclerView.getAdapter() != null) { childView = layoutMgr.findViewByPosition(pos); // avoid exception: audio playing and doing checked notes operation at non-playing page if (childView == null) return; childView.measure(UNBOUNDED, UNBOUNDED); itemHeight = childView.getMeasuredHeight(); // System.out.println("---------------- itemHeight = " + itemHeight); } // dividerHeight = recyclerView.getDividerHeight();//todo temp dividerHeight = 0; // System.out.println("---------------- dividerHeight = " + dividerHeight); firstVisible_note_pos = layoutMgr.findFirstVisibleItemPosition(); // System.out.println("---------------- firstVisible_note_pos = " + firstVisible_note_pos); v = recyclerView.getChildAt(0); int firstVisibleNote_top = (v == null) ? 0 : v.getTop(); // System.out.println("---------------- firstVisibleNote_top = " + firstVisibleNote_top); // System.out.println("---------------- Audio_manager.mAudioPos = " + Audio_manager.mAudioPos); if (firstVisibleNote_top < 0) { // restore index and top position recyclerView.scrollBy(0, firstVisibleNote_top); // System.out.println("----- scroll backwards by firstVisibleNote_top " + firstVisibleNote_top); } boolean noScroll = false; // base on Audio_manager.mAudioPos to scroll if (firstVisible_note_pos != Audio_manager.mAudioPos) { while ((firstVisible_note_pos != Audio_manager.mAudioPos) && (!noScroll)) { int offset = itemHeight + dividerHeight; // scroll forwards if (firstVisible_note_pos > Audio_manager.mAudioPos) { recyclerView.scrollBy(0, -offset); // System.out.println("-----scroll forwards (to top)" + (-offset)); } // scroll backwards else if (firstVisible_note_pos < Audio_manager.mAudioPos) { // when real item height could be larger than visible item height, so // scroll twice here in odder to do scroll successfully, otherwise scroll could fail recyclerView.scrollBy(0, offset / 2); recyclerView.scrollBy(0, offset / 2); // System.out.println("-----scroll backwards (to bottom) " + offset); } // System.out.println("---------------- firstVisible_note_pos = " + firstVisible_note_pos); // System.out.println("---------------- Page.drag_listView.getFirstVisiblePosition() = " + listView.getFirstVisiblePosition()); if (firstVisible_note_pos == layoutMgr.findFirstVisibleItemPosition()) noScroll = true; else { // update first visible index firstVisible_note_pos = layoutMgr.findFirstVisibleItemPosition(); } } // do v scroll TabsHost.store_listView_vScroll(recyclerView); TabsHost.resume_listView_vScroll(recyclerView); } }