Java Code Examples for android.view.View.getMeasuredHeight()

The following are Jave code examples for showing how to use getMeasuredHeight() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: GxIconDIY   File: BottomNavigationBehavior.java   Source Code and License Vote up 7 votes
@Override
public void updateSnackbar(CoordinatorLayout parent, View dependency, View child) {
    if (dependency instanceof Snackbar.SnackbarLayout) {
        if (mSnackbarHeight == -1) {
            mSnackbarHeight = dependency.getHeight();
        }

        int targetPadding = child.getMeasuredHeight();

        int shadow = (int) ViewCompat.getElevation(child);
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) dependency.getLayoutParams();
        layoutParams.bottomMargin = targetPadding - shadow;
        child.bringToFront();
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            child.getParent().requestLayout();
            ((View) child.getParent()).invalidate();
        }

    }
}
 
Example 2
Project: Android-UtilCode   File: SizeUtils.java   Source Code and License Vote up 6 votes
/**
 * 测量视图尺寸
 *
 * @param view 视图
 * @return arr[0]: 视图宽度, arr[1]: 视图高度
 */
public static int[] measureView(View view) {
    ViewGroup.LayoutParams lp = view.getLayoutParams();
    if (lp == null) {
        lp = new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT
        );
    }
    int widthSpec = ViewGroup.getChildMeasureSpec(0, 0, lp.width);
    int lpHeight = lp.height;
    int heightSpec;
    if (lpHeight > 0) {
        heightSpec = View.MeasureSpec.makeMeasureSpec(lpHeight, View.MeasureSpec.EXACTLY);
    } else {
        heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    }
    view.measure(widthSpec, heightSpec);
    return new int[]{view.getMeasuredWidth(), view.getMeasuredHeight()};
}
 
Example 3
Project: HiBangClient   File: RegSchoolActivity.java   Source Code and License Vote up 6 votes
/***
 * 动态设置listview的高度
 * 
 * @param listView
 */
public void setListViewHeightBasedOnChildren(ListView listView) {
	ListAdapter listAdapter = listView.getAdapter();
	if (listAdapter == null) {
		return;
	}
	int totalHeight = 0;
	for (int i = 0; i < listAdapter.getCount(); i++) {
		View listItem = listAdapter.getView(i, null, listView);
		listItem.measure(0, 0);
		totalHeight += listItem.getMeasuredHeight();
	}
	ViewGroup.LayoutParams params = listView.getLayoutParams();
	params.height = totalHeight
			+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
	// params.height += 5;// if without this statement,the listview will be
	// a
	// little short
	// listView.getDividerHeight()获取子项间分隔符占用的高度
	// params.height最后得到整个ListView完整显示需要的高度
	listView.setLayoutParams(params);
}
 
Example 4
Project: BluetoothAPP   File: ListViewHeightMesure.java   Source Code and License Vote up 6 votes
public static void setAdapterHeight(ListView listView){

        android.widget.ListAdapter listAdapter = listView.getAdapter();//1、获取adapter
        if (listAdapter == null) {
            return;
        }

        int totalHeight = 0;
        for (int i = 0,j =listAdapter.getCount(); i < j ; i++) {  //2、算出没一个item高度总和
            View listItem = listAdapter.getView(i , null, listView);
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }

        ViewGroup.LayoutParams params=listView.getLayoutParams();
        params.height = totalHeight + listView.getPaddingBottom()   //3、加上listview自身每行间距属性
                + listView.getPaddingTop()
                + (listView.getDividerHeight() * (listAdapter.getCount() - 1));


        listView.setLayoutParams(params);//4、重新设置高
    }
 
Example 5
Project: FlickLauncher   File: DragLayer.java   Source Code and License Vote up 5 votes
public void animateViewIntoPosition(DragView dragView, final View child, int duration,
        final Runnable onFinishAnimationRunnable, View anchorView) {
    ShortcutAndWidgetContainer parentChildren = (ShortcutAndWidgetContainer) child.getParent();
    CellLayout.LayoutParams lp =  (CellLayout.LayoutParams) child.getLayoutParams();
    parentChildren.measureChild(child);

    Rect r = new Rect();
    getViewRectRelativeToSelf(dragView, r);

    int coord[] = new int[2];
    float childScale = child.getScaleX();
    coord[0] = lp.x + (int) (child.getMeasuredWidth() * (1 - childScale) / 2);
    coord[1] = lp.y + (int) (child.getMeasuredHeight() * (1 - childScale) / 2);

    // Since the child hasn't necessarily been laid out, we force the lp to be updated with
    // the correct coordinates (above) and use these to determine the final location
    float scale = getDescendantCoordRelativeToSelf((View) child.getParent(), coord);
    // We need to account for the scale of the child itself, as the above only accounts for
    // for the scale in parents.
    scale *= childScale;
    int toX = coord[0];
    int toY = coord[1];
    float toScale = scale;
    if (child instanceof TextView) {
        TextView tv = (TextView) child;
        // Account for the source scale of the icon (ie. from AllApps to Workspace, in which
        // the workspace may have smaller icon bounds).
        toScale = scale / dragView.getIntrinsicIconScaleFactor();

        // The child may be scaled (always about the center of the view) so to account for it,
        // we have to offset the position by the scaled size.  Once we do that, we can center
        // the drag view about the scaled child view.
        toY += Math.round(toScale * tv.getPaddingTop());
        toY -= dragView.getMeasuredHeight() * (1 - toScale) / 2;
        if (dragView.getDragVisualizeOffset() != null) {
            toY -=  Math.round(toScale * dragView.getDragVisualizeOffset().y);
        }

        toX -= (dragView.getMeasuredWidth() - Math.round(scale * child.getMeasuredWidth())) / 2;
    } else if (child instanceof FolderIcon) {
        // Account for holographic blur padding on the drag view
        toY += Math.round(scale * (child.getPaddingTop() - dragView.getDragRegionTop()));
        toY -= scale * Workspace.DRAG_BITMAP_PADDING / 2;
        toY -= (1 - scale) * dragView.getMeasuredHeight() / 2;
        // Center in the x coordinate about the target's drawable
        toX -= (dragView.getMeasuredWidth() - Math.round(scale * child.getMeasuredWidth())) / 2;
    } else {
        toY -= (Math.round(scale * (dragView.getHeight() - child.getMeasuredHeight()))) / 2;
        toX -= (Math.round(scale * (dragView.getMeasuredWidth()
                - child.getMeasuredWidth()))) / 2;
    }

    final int fromX = r.left;
    final int fromY = r.top;
    child.setVisibility(INVISIBLE);
    Runnable onCompleteRunnable = new Runnable() {
        public void run() {
            child.setVisibility(VISIBLE);
            if (onFinishAnimationRunnable != null) {
                onFinishAnimationRunnable.run();
            }
        }
    };
    animateViewIntoPosition(dragView, fromX, fromY, toX, toY, 1, 1, 1, toScale, toScale,
            onCompleteRunnable, ANIMATION_END_DISAPPEAR, duration, anchorView);
}
 
Example 6
Project: FlickLauncher   File: WidgetsRecyclerView.java   Source Code and License Vote up 5 votes
/**
 * Returns the available scroll height:
 *   AvailableScrollHeight = Total height of the all items - last page height
 */
@Override
protected int getAvailableScrollHeight() {
    View child = getChildAt(0);
    int height = child.getMeasuredHeight() * mWidgets.getPackageSize();
    int totalHeight = getPaddingTop() + height + getPaddingBottom();
    int availableScrollHeight = totalHeight - getVisibleHeight();
    return availableScrollHeight;
}
 
Example 7
Project: android-BlankSpace   File: BlankSpacePopup.java   Source Code and License Vote up 5 votes
public void show(View anchor, int xOff, int yOff) {
    if(!isShowing()) {
        this.blankWindow = new PopupWindow(this.blankView, anchor.getMeasuredWidth() - xOff, anchor.getMeasuredHeight() - yOff);
        this.blankWindow.setAnimationStyle(this.animation);
        if(this.animationStyle != -1) this.blankWindow.setAnimationStyle(animationStyle);
        this.blankWindow.showAtLocation(anchor, Gravity.CENTER, 0, anchor.getHeight());
        this.isShowing = true;
    }
}
 
Example 8
Project: weex-3d-map   File: ViewUtil.java   Source Code and License Vote up 5 votes
public static int getHeight(View view)
{
    int w = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
    int h = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
    view.measure(w, h);
    return (view.getMeasuredHeight());
}
 
Example 9
Project: AndroidTvDemo   File: BaseEffectBridgeWrapper.java   Source Code and License Vote up 5 votes
public void flyWhiteBorder(final View focusView, View moveView, float scaleX, float scaleY)
{
    int newWidth = 0;
    int newHeight = 0;
    int oldWidth = 0;
    int oldHeight = 0;
    
    int newX = 0;
    int newY = 0;
    
    if (focusView != null)
    {
        newWidth = (int)(focusView.getMeasuredWidth() * scaleX);
        newHeight = (int)(focusView.getMeasuredHeight() * scaleY);
        oldWidth = moveView.getMeasuredWidth();
        oldHeight = moveView.getMeasuredHeight();
        Rect fromRect = findLocationWithView(moveView);
        Rect toRect = findLocationWithView(focusView);
        int x = toRect.left - fromRect.left;
        int y = toRect.top - fromRect.top;
        newX = x - Math.abs(focusView.getMeasuredWidth() - newWidth) / 2;
        newY = y - Math.abs(focusView.getMeasuredHeight() - newHeight) / 2;
    }
    
    ObjectAnimator transAnimatorX = ObjectAnimator.ofFloat(moveView, "translationX", newX);
    ObjectAnimator transAnimatorY = ObjectAnimator.ofFloat(moveView, "translationY", newY);
    // BUG,因为缩放会造成图片失真(拉伸).
    // hailong.qiu 2016.02.26 修复 :)
    ObjectAnimator scaleXAnimator = ObjectAnimator.ofInt(new ScaleView(moveView), "width", oldWidth, (int)newWidth);
    ObjectAnimator scaleYAnimator =
        ObjectAnimator.ofInt(new ScaleView(moveView), "height", oldHeight, (int)newHeight);
    //
    AnimatorSet mAnimatorSet = new AnimatorSet();
    mAnimatorSet.playTogether(transAnimatorX, transAnimatorY, scaleXAnimator, scaleYAnimator);
    mAnimatorSet.setInterpolator(new DecelerateInterpolator(1));
    mAnimatorSet.setDuration(DEFAULT_TRAN_DUR_ANIM);
    mAnimatorSet.start();
}
 
Example 10
Project: letv   File: HListView.java   Source Code and License Vote up 5 votes
@TargetApi(11)
private void setupChild(View child, int position, int x, boolean flowDown, int childrenTop, boolean selected, boolean recycled) {
    boolean isSelected = selected && shouldShowSelector();
    boolean updateChildSelected = isSelected != child.isSelected();
    int mode = this.mTouchMode;
    boolean isPressed = mode > 0 && mode < 3 && this.mMotionPosition == position;
    boolean updateChildPressed = isPressed != child.isPressed();
    boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();
    LayoutParams p = (LayoutParams) child.getLayoutParams();
    if (p == null) {
        p = (LayoutParams) generateDefaultLayoutParams();
    }
    p.viewType = this.mAdapter.getItemViewType(position);
    if ((!recycled || p.forceAdd) && !(p.recycledHeaderFooter && p.viewType == -2)) {
        p.forceAdd = false;
        if (p.viewType == -2) {
            p.recycledHeaderFooter = true;
        }
        addViewInLayout(child, flowDown ? -1 : 0, p, true);
    } else {
        attachViewToParent(child, flowDown ? -1 : 0, p);
    }
    if (updateChildSelected) {
        child.setSelected(isSelected);
    }
    if (updateChildPressed) {
        child.setPressed(isPressed);
    }
    if (!(this.mChoiceMode == 0 || this.mCheckStates == null)) {
        if (child instanceof Checkable) {
            ((Checkable) child).setChecked(((Boolean) this.mCheckStates.get(position, Boolean.valueOf(false))).booleanValue());
        } else if (VERSION.SDK_INT >= 11) {
            child.setActivated(((Boolean) this.mCheckStates.get(position, Boolean.valueOf(false))).booleanValue());
        }
    }
    if (needToMeasure) {
        int childWidthSpec;
        int childHeightSpec = ViewGroup.getChildMeasureSpec(this.mHeightMeasureSpec, 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);
    } else {
        cleanupLayoutState(child);
    }
    int w = child.getMeasuredWidth();
    int h = child.getMeasuredHeight();
    int childLeft = flowDown ? x : x - w;
    if (needToMeasure) {
        child.layout(childLeft, childrenTop, childLeft + w, childrenTop + h);
    } else {
        child.offsetLeftAndRight(childLeft - child.getLeft());
        child.offsetTopAndBottom(childrenTop - child.getTop());
    }
    if (this.mCachingStarted && !child.isDrawingCacheEnabled()) {
        child.setDrawingCacheEnabled(true);
    }
    if (VERSION.SDK_INT >= 11 && recycled && ((LayoutParams) child.getLayoutParams()).scrappedFromPosition != position) {
        child.jumpDrawablesToCurrentState();
    }
}
 
Example 11
Project: OSchina_resources_android   File: BannerView.java   Source Code and License Vote up 5 votes
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int childCount = getChildCount();
    for (int i = -1; i < childCount - 1; i++) {
        View childView = getChildAt(i + 1);
        int childW = childView.getMeasuredWidth();
        int childH = childView.getMeasuredHeight();
        int left, right, top, bottom;
        if (i == -1) {
            if (getChildCount() == 1) {
                left = mTotalScrollX + 2 * (int) mHorizontalOffset;
                right = childW + mTotalScrollX + (int) mHorizontalOffset;
                top = 3 * (int) mVerticalOffset / 2;
                bottom = top + childH;
            } else {
                left = -childW + mTotalScrollX + 2 * (int) mHorizontalOffset;
                right = mTotalScrollX + (int) mHorizontalOffset;
                top = 3 * (int) mVerticalOffset / 2;
                bottom = top + childH;
            }
        } else if (i == 0) {//当前居中项
            left = mTotalScrollX + (int) mHorizontalOffset;
            right = left + childW;
            top = (int) mVerticalOffset;
            bottom = top + childH;
        } else {
            left = childW + mTotalScrollX + (int) mHorizontalOffset;
            right = left + childW;
            top = 3 * (int) mVerticalOffset / 2;
            bottom = top + childH;
        }

        childView.layout(left, top, right, bottom);
    }
}
 
Example 12
Project: LaunchEnr   File: WidgetsRecyclerView.java   Source Code and License Vote up 5 votes
@Override
public int getCurrentScrollY() {
    // Skip early if widgets are not bound.
    if (isModelNotReady() || getChildCount() == 0) {
        return -1;
    }

    View child = getChildAt(0);
    int rowIndex = getChildLayoutPosition(child);
    int y = (child.getMeasuredHeight() * rowIndex);
    int offset = getLayoutManager().getDecoratedTop(child);

    return getPaddingTop() + y - offset;
}
 
Example 13
Project: UCMainViewForBehavior   File: UCViewContentBehavior.java   Source Code and License Vote up 5 votes
@Override
protected int getScrollRange(View dependency) {

    if(isDependency(dependency)) {
        //UCViewHeader的高度,减去UCViewTab和UCViewTitle的高度就是UCViewContent要滑动的高度
        return dependency.getMeasuredHeight() - mTitleViewHeight - mTabViewHeight;
    }
    return super.getScrollRange(dependency);
}
 
Example 14
Project: tenor-android-core   File: MeasurableViewHolderHelper.java   Source Code and License Vote up 4 votes
/**
 * Get the visible fraction of the given  {@link View} in the given {@link RecyclerView}
 *
 * @param recyclerView the given {@link RecyclerView}
 * @param itemView     the given {@link View}
 * @param threshold    the percentage of a view's area to be shown in order to consider it as being viewed
 * @return the visible fraction of the given  {@link View} in the given {@link RecyclerView}
 */
@FloatRange(from = 0.01f, to = 1f)
public static float calculateVisibleFraction(@NonNull RecyclerView recyclerView,
                                             @NonNull View itemView,
                                             float threshold) {
    /*
     * Special distributive measuring approach to handle the following issues:
     *
     * [ANDROID-1776]
     * view just went off visible region will report visible width equals to
     * the actual width of the width due to pre-caching
     *
     * [ANDROID-1786]
     * Incorrect reporting of in/visible status on some OEMs
     * issue caused by OEM custom implementation on how to define
     * the left and right of a off visible region
     *
     * Stock OS define off visible region left as negative number,
     * whereas some other OEM defines it as 0, so use #getLocationInWindow() instead
     */
    Rect ivRect = new Rect();
    itemView.getGlobalVisibleRect(ivRect);
    if (ivRect.isEmpty()) {
        return 0.01f;
    }

    Rect rvRect = new Rect();
    recyclerView.getGlobalVisibleRect(rvRect);

    int[] location = new int[2];
    itemView.getLocationInWindow(location);

    final boolean rtl = AbstractUIUtils.isRightToLeft(recyclerView.getContext());
    final int width = itemView.getMeasuredWidth();
    final int height = itemView.getMeasuredHeight();

    // ratio for left bound
    final float leftBoundRatio;
    if (!rtl) {
        // left to right languages
        leftBoundRatio = 1f - threshold;
    } else {
        // right to left languages
        leftBoundRatio = threshold;
    }

    final int left = (int) (rvRect.left - leftBoundRatio * width);
    final int right = (int) (rvRect.right - (1f - leftBoundRatio) * width);
    final int top = (int) (rvRect.top - (1f - threshold) * height);
    final int bottom = (int) (rvRect.bottom - threshold * height);

    // horizontally out of bound
    final boolean hoob = location[0] < left || location[0] > right;

    // vertically out of bound
    final boolean voob = location[1] < top || location[1] > bottom;
    if (hoob || voob) {
        return 0.01f;
    }

    float wRatio = (float) ivRect.width() / width;
    float hRatio = (float) ivRect.height() / height;

    /*
     * the non-moving direction will be always 1.0f,
     * so the direction of interest is the smaller one of the two,
     * and the final number is capped between 0.01f and 1.0f
     */
    float percentage = Math.min(wRatio, hRatio);
    percentage = Math.min(percentage, 1f);
    percentage = Math.max(percentage, 0.01f);
    return percentage;
}
 
Example 15
Project: SlidingUpPanelLayout   File: SlidingUpPanelLayout.java   Source Code and License Vote up 4 votes
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final int paddingLeft = getPaddingLeft();
    final int paddingTop = getPaddingTop();

    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (i == 0 && child instanceof ISlidingUpPanel) {
            throw new IllegalArgumentException("The child view at position 0 can't be an instance of ISlidingUpPanel! ");
        }
        if (i > 0 && !(child instanceof ISlidingUpPanel)) {
            throw new IllegalArgumentException("The child view after position 0 must be an instance of ISlidingUpPanel! ");
        }

        if (isFirstLayout && child instanceof ISlidingUpPanel) {
            if (mSlidingUpPanel == null) {
                mSlidingUpPanel = (ISlidingUpPanel) child;
            }
            setOnTouchedInternal(child);
        }

        // Always layout the sliding view on the first layout
        if (child.getVisibility() == GONE && (i == 0 || isFirstLayout)) {
            continue;
        }

        int childTop = paddingTop;

        MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
        childTop += lp.topMargin;
        int childBottom = childTop + child.getMeasuredHeight();
        int childLeft = paddingLeft + lp.leftMargin;
        int childRight = childLeft + child.getMeasuredWidth();

        if (child instanceof ISlidingUpPanel) {
            ISlidingUpPanel panel = (ISlidingUpPanel) child;
            childTop = panel.getPanelTopBySlidingState(panel.getSlideState()) + getPaddingTop();
            childBottom = childTop + ((ISlidingUpPanel) child).getPanelExpandedHeight();
        }

        child.layout(childLeft, childTop, childRight, childBottom);
    }

    isFirstLayout = false;
}
 
Example 16
Project: chalkboard   File: About.java   Source Code and License Vote up 4 votes
private void setListViewHeightBasedOnChildren() {

        if (listAdapter == null)
            return;

        int totalHeight = 0;

        for (int i = 0; i < listAdapter.getCount(); i++) {

            final View listItem = listAdapter.getView(i, null, listView);
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();

        }

        final ViewGroup.LayoutParams listViewLayoutParams = listView.getLayoutParams();
        listViewLayoutParams.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
        listView.setLayoutParams(listViewLayoutParams);

    }
 
Example 17
Project: mvvm-template   File: AutoLinearLayout.java   Source Code and License Vote up 4 votes
private void measureVertical(int widthMeasureSpec, int heightMeasureSpec) {
    int hSize = MeasureSpec.getSize(heightMeasureSpec) - (getPaddingTop() + getPaddingBottom());

    int count = getChildCount();
    int columnHeight = 0;
    int totalWidth = 0, maxColumnHeight = 0;
    int columnMaxWidth = 0;
    int childWidth;
    int childHeight;

    //Scrollview case
    if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.UNSPECIFIED)
        hSize = Integer.MAX_VALUE;

    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            childWidth = child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
            childHeight = child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
            //keep max width value stored
            columnMaxWidth = Math.max(columnMaxWidth, childWidth);

            //exceed max height start new column and update total width
            if (childHeight + columnHeight > hSize) {
                totalWidth += columnMaxWidth;
                maxColumnHeight = Math.max(maxColumnHeight, columnHeight);
                columnHeight = childHeight;
                columnMaxWidth = childWidth;
            } else {
                columnHeight += childHeight;
            }
        }
    }
    //plus last child width
    if (columnHeight != 0) {
        maxColumnHeight = Math.max(maxColumnHeight, columnHeight);
        totalWidth += columnMaxWidth;
    }

    //set height to max value
    if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.UNSPECIFIED)
        hSize = maxColumnHeight + (getPaddingTop() + getPaddingBottom());

    setMeasuredDimension(resolveSize(totalWidth + getPaddingRight() + getPaddingLeft(),
            widthMeasureSpec), resolveSize(hSize, heightMeasureSpec));
}
 
Example 18
Project: Toodoo   File: FloatingActionMenu.java   Source Code and License Vote up 4 votes
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int buttonsHorizontalCenter = mLabelsPosition == LABELS_POSITION_LEFT
            ? r - l - mMaxButtonWidth / 2 - getPaddingRight()
            : mMaxButtonWidth / 2 + getPaddingLeft();
    boolean openUp = mOpenDirection == OPEN_UP;

    int menuButtonTop = openUp
            ? b - t - mMenuButton.getMeasuredHeight() - getPaddingBottom()
            : getPaddingTop();
    int menuButtonLeft = buttonsHorizontalCenter - mMenuButton.getMeasuredWidth() / 2;

    mMenuButton.layout(menuButtonLeft, menuButtonTop, menuButtonLeft + mMenuButton.getMeasuredWidth(),
            menuButtonTop + mMenuButton.getMeasuredHeight());

    int imageLeft = buttonsHorizontalCenter - mImageToggle.getMeasuredWidth() / 2;
    int imageTop = menuButtonTop + mMenuButton.getMeasuredHeight() / 2 - mImageToggle.getMeasuredHeight() / 2;

    mImageToggle.layout(imageLeft, imageTop, imageLeft + mImageToggle.getMeasuredWidth(),
            imageTop + mImageToggle.getMeasuredHeight());

    int nextY = openUp
            ? menuButtonTop + mMenuButton.getMeasuredHeight() + mButtonSpacing
            : menuButtonTop;

    for (int i = mButtonsCount - 1; i >= 0; i--) {
        View child = getChildAt(i);

        if (child == mImageToggle) continue;

        FloatingActionButton fab = (FloatingActionButton) child;

        if (fab.getVisibility() == GONE) continue;

        int childX = buttonsHorizontalCenter - fab.getMeasuredWidth() / 2;
        int childY = openUp ? nextY - fab.getMeasuredHeight() - mButtonSpacing : nextY;

        if (fab != mMenuButton) {
            fab.layout(childX, childY, childX + fab.getMeasuredWidth(),
                    childY + fab.getMeasuredHeight());

            if (!mIsMenuOpening) {
                fab.hide(false);
            }
        }

        View label = (View) fab.getTag(R.id.fab_label);
        if (label != null) {
            int labelsOffset = (mUsingMenuLabel ? mMaxButtonWidth / 2 : fab.getMeasuredWidth() / 2) + mLabelsMargin;
            int labelXNearButton = mLabelsPosition == LABELS_POSITION_LEFT
                    ? buttonsHorizontalCenter - labelsOffset
                    : buttonsHorizontalCenter + labelsOffset;

            int labelXAwayFromButton = mLabelsPosition == LABELS_POSITION_LEFT
                    ? labelXNearButton - label.getMeasuredWidth()
                    : labelXNearButton + label.getMeasuredWidth();

            int labelLeft = mLabelsPosition == LABELS_POSITION_LEFT
                    ? labelXAwayFromButton
                    : labelXNearButton;

            int labelRight = mLabelsPosition == LABELS_POSITION_LEFT
                    ? labelXNearButton
                    : labelXAwayFromButton;

            int labelTop = childY - mLabelsVerticalOffset + (fab.getMeasuredHeight()
                    - label.getMeasuredHeight()) / 2;

            label.layout(labelLeft, labelTop, labelRight, labelTop + label.getMeasuredHeight());

            if (!mIsMenuOpening) {
                label.setVisibility(INVISIBLE);
            }
        }

        nextY = openUp
                ? childY - mButtonSpacing
                : childY + child.getMeasuredHeight() + mButtonSpacing;
    }
}
 
Example 19
Project: letv   File: ViewPager.java   Source Code and License Vote up 4 votes
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int i;
    LayoutParams lp;
    setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));
    int measuredWidth = getMeasuredWidth();
    this.mGutterSize = Math.min(measuredWidth / 10, this.mDefaultGutterSize);
    int childWidthSize = (measuredWidth - getPaddingLeft()) - getPaddingRight();
    int childHeightSize = (getMeasuredHeight() - getPaddingTop()) - getPaddingBottom();
    int size = getChildCount();
    for (i = 0; i < size; i++) {
        View child = getChildAt(i);
        if (child.getVisibility() != 8) {
            lp = (LayoutParams) child.getLayoutParams();
            if (lp != null && lp.isDecor) {
                int hgrav = lp.gravity & 7;
                int vgrav = lp.gravity & 112;
                int widthMode = Integer.MIN_VALUE;
                int heightMode = Integer.MIN_VALUE;
                boolean consumeVertical = vgrav == 48 || vgrav == 80;
                boolean consumeHorizontal = hgrav == 3 || hgrav == 5;
                if (consumeVertical) {
                    widthMode = 1073741824;
                } else if (consumeHorizontal) {
                    heightMode = 1073741824;
                }
                int widthSize = childWidthSize;
                int heightSize = childHeightSize;
                if (lp.width != -2) {
                    widthMode = 1073741824;
                    if (lp.width != -1) {
                        widthSize = lp.width;
                    }
                }
                if (lp.height != -2) {
                    heightMode = 1073741824;
                    if (lp.height != -1) {
                        heightSize = lp.height;
                    }
                }
                child.measure(MeasureSpec.makeMeasureSpec(widthSize, widthMode), MeasureSpec.makeMeasureSpec(heightSize, heightMode));
                if (consumeVertical) {
                    childHeightSize -= child.getMeasuredHeight();
                } else if (consumeHorizontal) {
                    childWidthSize -= child.getMeasuredWidth();
                }
            }
        }
    }
    this.mChildWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, 1073741824);
    this.mChildHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeightSize, 1073741824);
    this.mInLayout = true;
    populate();
    this.mInLayout = false;
    size = getChildCount();
    for (i = 0; i < size; i++) {
        child = getChildAt(i);
        if (child.getVisibility() != 8) {
            lp = (LayoutParams) child.getLayoutParams();
            if (lp == null || !lp.isDecor) {
                child.measure(MeasureSpec.makeMeasureSpec((int) (((float) childWidthSize) * lp.widthFactor), 1073741824), this.mChildHeightMeasureSpec);
            }
        }
    }
}
 
Example 20
Project: GitHub   File: OverScrollProcessor.java   Source Code and License Vote up 4 votes
@Override
public void handleMessage(Message msg) {
    switch (msg.what) {
        case MSG_START_COMPUTE_SCROLL:
            cur_delay_times = -1; //这里没有break,写作-1方便计数
        case MSG_CONTINUE_COMPUTE_SCROLL:
            cur_delay_times++;

            View mChildView = cp.getContent();

            if (!(mChildView instanceof AbsListView || mChildView instanceof RecyclerView)) {

                if (cp.allowOverScroll() && mVelocityY >= OVER_SCROLL_MIN_VX && (mChildView != null && Math.abs(mChildView.getScrollY()) <= 2 * mTouchSlop)) {
                    cp.getAnimProcessor().animOverScrollTop(mVelocityY, cur_delay_times);
                    mVelocityY = 0;
                    cur_delay_times = ALL_DELAY_TIMES;
                }

                if (cp.allowOverScroll() && mVelocityY <= -OVER_SCROLL_MIN_VX && mChildView != null) {
                    if (mChildView instanceof WebView) {
                        WebView webview = (WebView) (mChildView);
                        if (Math.abs(webview.getContentHeight() * webview.getScale() - (webview.getHeight() + webview.getScrollY())) <= 2 * mTouchSlop) {
                            cp.getAnimProcessor().animOverScrollBottom(mVelocityY, cur_delay_times);
                            mVelocityY = 0;
                            cur_delay_times = ALL_DELAY_TIMES;
                        }
                    } else if (mChildView instanceof ViewGroup) {
                        View subChildView = ((ViewGroup) mChildView).getChildAt(0);
                        if (subChildView != null && subChildView.getMeasuredHeight() <= mChildView.getScrollY() + mChildView.getHeight()) {
                            //滚动到了底部
                            cp.getAnimProcessor().animOverScrollBottom(mVelocityY, cur_delay_times);
                            mVelocityY = 0;
                            cur_delay_times = ALL_DELAY_TIMES;
                        }
                    } else if (mChildView.getScrollY() >= mChildView.getHeight()) {
                        cp.getAnimProcessor().animOverScrollBottom(mVelocityY, cur_delay_times);
                        mVelocityY = 0;
                        cur_delay_times = ALL_DELAY_TIMES;
                    }
                }
            }

            if (cur_delay_times < ALL_DELAY_TIMES)
                mHandler.sendEmptyMessageDelayed(MSG_CONTINUE_COMPUTE_SCROLL, 10);
            break;
        case MSG_STOP_COMPUTE_SCROLL:
            cur_delay_times = ALL_DELAY_TIMES;
            break;
    }
}