List of usage examples for android.view View getMeasuredWidth
public final int getMeasuredWidth()
From source file:cn.jay.widget.BottomNavigationMenuView.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int width = MeasureSpec.getSize(widthMeasureSpec); final int count = getChildCount(); final int childState = 0; final int heightSpec = MeasureSpec.makeMeasureSpec(mItemHeight, MeasureSpec.EXACTLY); final int[] childWidths = new int[count]; if (mShiftingMode && mUseStandardDesign) { final int inactiveCount = count - 1; final int activeMaxAvailable = width - inactiveCount * mInactiveItemMinWidth; final int activeWidth = Math.min(activeMaxAvailable, mActiveItemMaxWidth); final int inactiveMaxAvailable = (width - activeWidth) / inactiveCount; final int inactiveWidth = Math.min(inactiveMaxAvailable, mInactiveItemMaxWidth); int extra = width - activeWidth - inactiveWidth * inactiveCount; for (int i = 0; i < count; i++) { childWidths[i] = (i == mActiveButton) ? activeWidth : inactiveWidth; if (extra > 0) { childWidths[i]++;/*from ww w .ja v a2 s .co m*/ extra--; } } } else { final int maxAvailable = width / count; final int childWidth = Math.min(maxAvailable, mActiveItemMaxWidth); int extra = width - childWidth * count; for (int i = 0; i < count; i++) { childWidths[i] = childWidth; if (extra > 0) { childWidths[i]++; extra--; } } } int totalWidth = 0; for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } child.measure(MeasureSpec.makeMeasureSpec(childWidths[i], MeasureSpec.EXACTLY), heightSpec); LayoutParams params = child.getLayoutParams(); params.width = child.getMeasuredWidth(); totalWidth += child.getMeasuredWidth(); } setMeasuredDimension( ViewCompat.resolveSizeAndState(totalWidth, MeasureSpec.makeMeasureSpec(totalWidth, MeasureSpec.EXACTLY), childState), ViewCompat.resolveSizeAndState(mItemHeight, heightSpec, childState << MEASURED_HEIGHT_STATE_SHIFT)); }
From source file:com.example.kuassivi.material_avatar.feature.ChooseAvatarActivity.java
/** * When the Fab view is tapped, deliver the image url saved on ProfileActivity * * @param v View//from ww w .ja va 2 s .co m */ @Override public void onClick(View v) { switch (v.getId()) { case R.id.fab: Intent returnIntent = new Intent(); returnIntent.putExtra(ProfileActivity.Extra.AVATAR_URL, mAvatarUrl); setResult(RESULT_OK, returnIntent); supportFinishAfterTransition(); ViewCompat.animate(v).translationX(v.getMeasuredWidth()).start(); break; } }
From source file:android.support.v17.leanback.widget.HorizontalHoverCardSwitcher.java
@Override protected void onViewSelected(View view) { int rightLimit = getParentViewGroup().getWidth() - getParentViewGroup().getPaddingRight(); int leftLimit = getParentViewGroup().getPaddingLeft(); // measure the hover card width; if it's too large, align hover card // end edge with row view's end edge, otherwise align start edges. view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); MarginLayoutParams params = (MarginLayoutParams) view.getLayoutParams(); boolean isRtl = ViewCompat.getLayoutDirection(view) == View.LAYOUT_DIRECTION_RTL; if (!isRtl && mCardLeft + view.getMeasuredWidth() > rightLimit) { params.leftMargin = rightLimit - view.getMeasuredWidth(); } else if (isRtl && mCardLeft < leftLimit) { params.leftMargin = leftLimit;/*from w ww . j ava 2 s. c om*/ } else if (isRtl) { params.leftMargin = mCardRight - view.getMeasuredWidth(); } else { params.leftMargin = mCardLeft; } view.requestLayout(); }
From source file:com.asc_ii.bangnote.bigbang.BigBangLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { int top;//from ww w. j a v a2 s . co m int left; int offsetTop; Line lastSelectedLine = findLastSelectedLine(); Line firstSelectedLine = findFirstSelectedLine(); for (int i = 0; i < mLines.size(); i++) { Line line = mLines.get(i); List<Item> items = line.getItems(); left = getPaddingLeft() + mActionBar.getContentPadding(); if (firstSelectedLine != null && firstSelectedLine.index > line.index) { offsetTop = -mActionBarTopHeight; } else if (lastSelectedLine != null && lastSelectedLine.index < line.index) { offsetTop = mActionBarBottomHeight; } else { offsetTop = 0; } for (int j = 0; j < items.size(); j++) { Item item = items.get(j); top = getPaddingTop() + i * (item.height + mLineSpace) + offsetTop + mActionBarTopHeight; View child = item.view; int oldTop = child.getTop(); child.layout(left, top, left + child.getMeasuredWidth(), top + child.getMeasuredHeight()); if (oldTop != top) { int translationY = oldTop - top; child.setTranslationY(translationY); child.animate().translationYBy(-translationY).setDuration(200).start(); } left += child.getMeasuredWidth() + mItemSpace; } } if (firstSelectedLine != null && lastSelectedLine != null) { mActionBar.setVisibility(View.VISIBLE); mActionBar.setAlpha(1); int oldTop = mActionBar.getTop(); int actionBarTop = firstSelectedLine.index * (firstSelectedLine.getHeight() + mLineSpace) + getPaddingTop(); mActionBar.layout(getPaddingLeft(), actionBarTop, getPaddingLeft() + mActionBar.getMeasuredWidth(), actionBarTop + mActionBar.getMeasuredHeight()); if (oldTop != actionBarTop) { int translationY = oldTop - actionBarTop; mActionBar.setTranslationY(translationY); mActionBar.animate().translationYBy(-translationY).setDuration(200).start(); } } else { if (mActionBar.getVisibility() == View.VISIBLE) { mActionBar.animate().alpha(0).setDuration(200).setListener(mActionBarAnimationListener).start(); } } }
From source file:com.flexible.flexibleadapter.helpers.StickyHeaderHelper.java
private void ensureHeaderParent() { final View view = mStickyHeaderViewHolder.getContentView(); // #121 - Make sure the measured height (width for horizontal layout) is kept if // WRAP_CONTENT has been set for the Header View mStickyHeaderViewHolder.itemView.getLayoutParams().width = view.getMeasuredWidth(); mStickyHeaderViewHolder.itemView.getLayoutParams().height = view.getMeasuredHeight(); // Ensure the itemView is hidden to avoid double background mStickyHeaderViewHolder.itemView.setVisibility(View.INVISIBLE); // #139 - Copy xml params instead of Measured params ViewGroup.LayoutParams params = mStickyHolderLayout.getLayoutParams(); params.width = mRecyclerView.getWidth(); params.height = view.getLayoutParams().height; removeViewFromParent(view);/*from w ww.j a va2s. co m*/ mStickyHolderLayout.addView(view); configureLayoutElevation(); }
From source file:com.bridgeconn.autographago.ui.customviews.TabLayoutHelper.java
protected int determineTabMode(@NonNull TabLayout tabLayout) { LinearLayout slidingTabStrip = (LinearLayout) tabLayout.getChildAt(0); int childCount = slidingTabStrip.getChildCount(); // NOTE: slidingTabStrip.getMeasuredWidth() method does not return correct width! // Need to measure each tabs and calculate the sum of them. int tabLayoutWidth = tabLayout.getMeasuredWidth() - tabLayout.getPaddingLeft() - tabLayout.getPaddingRight(); int tabLayoutHeight = tabLayout.getMeasuredHeight() - tabLayout.getPaddingTop() - tabLayout.getPaddingBottom(); if (childCount == 0) { return TabLayout.MODE_FIXED; }/* www .ja v a 2 s . c o m*/ int stripWidth = 0; int maxWidthTab = 0; int tabHeightMeasureSpec = View.MeasureSpec.makeMeasureSpec(tabLayoutHeight, View.MeasureSpec.EXACTLY); for (int i = 0; i < childCount; i++) { View tabView = slidingTabStrip.getChildAt(i); tabView.measure(View.MeasureSpec.UNSPECIFIED, tabHeightMeasureSpec); int tabWidth = tabView.getMeasuredWidth(); stripWidth += tabWidth; maxWidthTab = Math.max(maxWidthTab, tabWidth); } return ((stripWidth < tabLayoutWidth) && (maxWidthTab < (tabLayoutWidth / childCount))) ? TabLayout.MODE_FIXED : TabLayout.MODE_SCROLLABLE; }
From source file:android.support.design.internal.BottomNavigationMenuView.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int width = MeasureSpec.getSize(widthMeasureSpec); final int count = getChildCount(); final int heightSpec = MeasureSpec.makeMeasureSpec(mItemHeight, MeasureSpec.EXACTLY); if (mShiftingMode) { final int inactiveCount = count - 1; final int activeMaxAvailable = width - inactiveCount * mInactiveItemMinWidth; final int activeWidth = Math.min(activeMaxAvailable, mActiveItemMaxWidth); final int inactiveMaxAvailable = (width - activeWidth) / inactiveCount; final int inactiveWidth = Math.min(inactiveMaxAvailable, mInactiveItemMaxWidth); int extra = width - activeWidth - inactiveWidth * inactiveCount; for (int i = 0; i < count; i++) { mTempChildWidths[i] = (i == mSelectedItemPosition) ? activeWidth : inactiveWidth; if (extra > 0) { mTempChildWidths[i]++;//ww w . ja v a 2 s. c o m extra--; } } } else { final int maxAvailable = width / (count == 0 ? 1 : count); final int childWidth = Math.min(maxAvailable, mActiveItemMaxWidth); int extra = width - childWidth * count; for (int i = 0; i < count; i++) { mTempChildWidths[i] = childWidth; if (extra > 0) { mTempChildWidths[i]++; extra--; } } } int totalWidth = 0; for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } child.measure(MeasureSpec.makeMeasureSpec(mTempChildWidths[i], MeasureSpec.EXACTLY), heightSpec); LayoutParams params = child.getLayoutParams(); params.width = child.getMeasuredWidth(); totalWidth += child.getMeasuredWidth(); } setMeasuredDimension( ViewCompat.resolveSizeAndState(totalWidth, MeasureSpec.makeMeasureSpec(totalWidth, MeasureSpec.EXACTLY), 0), ViewCompat.resolveSizeAndState(mItemHeight, heightSpec, 0)); }
From source file:com.aizou.core.widget.pagerIndicator.indicator.FixedIndicatorView.java
private void measureScrollBar(boolean needChange) { if (scrollBar == null) return;// www . j a v a2s .c o m View view = scrollBar.getSlideView(); if (view.isLayoutRequested() || needChange) { if (mAdapter != null && mAdapter.getCount() > 0 && mSelectedTabIndex >= 0 && mSelectedTabIndex < mAdapter.getCount()) { int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), mWidthMode); int heightSpec; ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); if (layoutParams != null && layoutParams.height > 0) { heightSpec = MeasureSpec.makeMeasureSpec(layoutParams.height, MeasureSpec.EXACTLY); } else { heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); } view.measure(widthSpec, heightSpec); View curr = getChildAt(mSelectedTabIndex); view.layout(0, 0, scrollBar.getWidth(curr.getMeasuredWidth()), scrollBar.getHeight(getHeight())); } } }
From source file:com.astuetz.viewpager.extensions.SwipeyTabsView.java
/** * {@inheritDoc}/*from ww w .j a va 2s . com*/ */ @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { final int paddingTop = getPaddingTop(); for (int i = 0; i < mTabsCount; i++) { final View tab = getChildAt(i); TabPosition pos = mPositions.get(i); if (tab instanceof SwipeyTab) { final int tabCenter = mPositions.get(i).currentPos + tab.getMeasuredWidth() / 2; final int diff = Math.abs(mCenter - tabCenter); final int p = (int) 100 * diff / mHighlightOffset; ((SwipeyTab) tab).setHighlightPercentage(diff <= mHighlightOffset ? 100 - p : 0); } tab.layout(pos.currentPos, paddingTop, pos.currentPos + pos.width, paddingTop + pos.height); } }
From source file:com.ab.view.sliding.AbSlidingTabView2.java
/** * /*from ww w . jav a 2s .c o m*/ * ??? * @param index * @throws */ public void computeTabImg(int index) { for (int i = 0; i < tabItemList.size(); i++) { TextView tv = tabItemList.get(i); tv.setTextColor(tabColor); tv.setSelected(false); if (index == i) { tv.setTextColor(tabSelectColor); tv.setSelected(true); } } // final View tabView = mTabLayout.getChildAt(index); AbViewUtil.measureView(tabView); LayoutParams mParams = new LayoutParams(tabView.getMeasuredWidth(), tabSlidingHeight); mParams.topMargin = -tabSlidingHeight; mTabImg.setLayoutParams(mParams); if (D) Log.d(TAG, "old--startX:" + startX); //????????tab if (D) Log.d(TAG, "view" + index + ":" + tabView.getMeasuredWidth()); if (D) Log.d(TAG, "ScrollView:" + mTabScrollView.getWidth()); if (D) Log.d(TAG, "scrollX:" + scrollX); if (D) Log.d(TAG, "tabView right:" + tabView.getRight()); if (D) Log.d(TAG, "tabView left:" + tabView.getLeft()); if (mSelectedTabIndex < index && tabView.getRight() - scrollX > mTabScrollView.getWidth()) { if (D) Log.d(TAG, "??"); int offsetX = 0; //?? if (index == mTabLayout.getChildCount() - 1) { offsetX = tabView.getRight() - mTabScrollView.getWidth() - scrollX; mTabScrollView.smoothScrollBy(offsetX, 0); scrollX = scrollX + offsetX; if (D) Log.d(TAG, "startX:" + startX + ",offsetX:" + offsetX); imageSlide(mTabImg, startX, mTabScrollView.getWidth() - tabView.getMeasuredWidth(), 0, 0); startX = mTabScrollView.getWidth() - tabView.getMeasuredWidth(); } else { offsetX = tabView.getMeasuredWidth(); mTabScrollView.smoothScrollBy(offsetX, 0); scrollX = scrollX + offsetX; if (D) Log.d(TAG, "startX:" + startX + ",offsetX:" + offsetX); int toX = tabView.getLeft() - scrollX; imageSlide(mTabImg, startX, toX, 0, 0); startX = toX; } } else if (mSelectedTabIndex > index && tabView.getLeft() < scrollX) { if (D) Log.d(TAG, "?"); //? offsetX int offsetX = 0; if (index == 0) { offsetX = -scrollX; mTabScrollView.smoothScrollBy(offsetX, 0); scrollX = scrollX + offsetX; imageSlide(mTabImg, startX, 0, 0, 0); startX = 0; } else { offsetX = -tabView.getMeasuredWidth(); mTabScrollView.smoothScrollBy(offsetX, 0); scrollX = scrollX + offsetX; if (D) Log.d(TAG, "startX2:" + startX + ",offsetX:" + offsetX); int toX = tabView.getLeft() - scrollX; imageSlide(mTabImg, startX, toX, 0, 0); startX = toX; } } else { int toX = tabView.getLeft() - scrollX; imageSlide(mTabImg, startX, toX, 0, 0); startX = toX; } mSelectedTabIndex = index; }