当前位置: 首页>>代码示例>>Java>>正文


Java View.getMeasuredHeight方法代码示例

本文整理汇总了Java中android.view.View.getMeasuredHeight方法的典型用法代码示例。如果您正苦于以下问题:Java View.getMeasuredHeight方法的具体用法?Java View.getMeasuredHeight怎么用?Java View.getMeasuredHeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.View的用法示例。


在下文中一共展示了View.getMeasuredHeight方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateSnackbar

import android.view.View; //导入方法依赖的package包/类
@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();
        }

    }
}
 
开发者ID:homeii,项目名称:GxIconDIY,代码行数:21,代码来源:BottomNavigationBehavior.java

示例2: measureView

import android.view.View; //导入方法依赖的package包/类
/**
 * 测量视图尺寸
 *
 * @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()};
}
 
开发者ID:hoangkien0705,项目名称:Android-UtilCode,代码行数:26,代码来源:SizeUtils.java

示例3: setListViewHeightBasedOnChildren

import android.view.View; //导入方法依赖的package包/类
/***
 * 动态设置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);
}
 
开发者ID:qizhenghao,项目名称:HiBangClient,代码行数:27,代码来源:RegSchoolActivity.java

示例4: setAdapterHeight

import android.view.View; //导入方法依赖的package包/类
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、重新设置高
    }
 
开发者ID:aiyangtianci,项目名称:BluetoothAPP,代码行数:23,代码来源:ListViewHeightMesure.java

示例5: animateViewIntoPosition

import android.view.View; //导入方法依赖的package包/类
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);
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:67,代码来源:DragLayer.java

示例6: getAvailableScrollHeight

import android.view.View; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:13,代码来源:WidgetsRecyclerView.java

示例7: show

import android.view.View; //导入方法依赖的package包/类
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;
    }
}
 
开发者ID:battleent,项目名称:android-BlankSpace,代码行数:10,代码来源:BlankSpacePopup.java

示例8: getHeight

import android.view.View; //导入方法依赖的package包/类
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());
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:8,代码来源:ViewUtil.java

示例9: flyWhiteBorder

import android.view.View; //导入方法依赖的package包/类
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();
}
 
开发者ID:Dreamxiaoxuan,项目名称:AndroidTvDemo,代码行数:39,代码来源:BaseEffectBridgeWrapper.java

示例10: setupChild

import android.view.View; //导入方法依赖的package包/类
@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();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:65,代码来源:HListView.java

示例11: onLayout

import android.view.View; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:36,代码来源:BannerView.java

示例12: getCurrentScrollY

import android.view.View; //导入方法依赖的package包/类
@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;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:15,代码来源:WidgetsRecyclerView.java

示例13: getScrollRange

import android.view.View; //导入方法依赖的package包/类
@Override
protected int getScrollRange(View dependency) {

    if(isDependency(dependency)) {
        //UCViewHeader的高度,减去UCViewTab和UCViewTitle的高度就是UCViewContent要滑动的高度
        return dependency.getMeasuredHeight() - mTitleViewHeight - mTabViewHeight;
    }
    return super.getScrollRange(dependency);
}
 
开发者ID:huyongli,项目名称:UCMainViewForBehavior,代码行数:10,代码来源:UCViewContentBehavior.java

示例14: calculateVisibleFraction

import android.view.View; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:Tenor-Inc,项目名称:tenor-android-core,代码行数:81,代码来源:MeasurableViewHolderHelper.java

示例15: onLayout

import android.view.View; //导入方法依赖的package包/类
@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;
}
 
开发者ID:woxingxiao,项目名称:SlidingUpPanelLayout,代码行数:48,代码来源:SlidingUpPanelLayout.java


注:本文中的android.view.View.getMeasuredHeight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。