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


Java View.getMeasuredWidth方法代码示例

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


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

示例1: measureScrapChild

import android.view.View; //导入方法依赖的package包/类
private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec,
                               int heightSpec, int[] measuredDimension) {
    try {
        View view = recycler.getViewForPosition(0);//fix 动态添加时报IndexOutOfBoundsException

        if (view != null) {
            RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();

            int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec,
                    getPaddingLeft() + getPaddingRight(), p.width);

            int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec,
                    getPaddingTop() + getPaddingBottom(), p.height);

            view.measure(childWidthSpec, childHeightSpec);
            measuredDimension[0] = view.getMeasuredWidth() + p.leftMargin + p.rightMargin;
            measuredDimension[1] = view.getMeasuredHeight() + p.bottomMargin + p.topMargin;
            recycler.recycleView(view);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
    }
}
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:25,代码来源:FullyLinearLayoutManager.java

示例2: onMeasure

import android.view.View; //导入方法依赖的package包/类
@Override
    protected void onMeasure(int widthMeasureSpec,int heightMeasureSpec) {
        // 父View 不能限制我们。模式是UNSPECIFIED  宽度所有子View宽总和, 高度取子View最大
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);

        int width = 0;
        int height = 0;

//        Log.i("feng",
//              "single 调用 onMeasure - widthMode :" + widthMode + " width size:  " + widthSize + " height size " + heightSize);

        for (int i = 0; i < getChildCount(); i++) {
            View childView = getChildAt(i);

            int widthChild = MeasureSpec.makeMeasureSpec(widthSize,MeasureSpec.UNSPECIFIED);
            int heightChild = MeasureSpec.makeMeasureSpec(heightSize,MeasureSpec.UNSPECIFIED);

            childView.measure(widthChild,heightChild);

            width += childView.getMeasuredWidth();
            height = Math.max(height,childView.getMeasuredHeight());
        }
        setMeasuredDimension(width,height);
    }
 
开发者ID:HYY-yu,项目名称:TableRecyclerView,代码行数:26,代码来源:SingleLineLinearLayout.java

示例3: measureScrapChild

import android.view.View; //导入方法依赖的package包/类
private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec,
                               int heightSpec, int[] measuredDimension) {
    try {
        View view = recycler.getViewForPosition(position);//fix 动态添加时报IndexOutOfBoundsException

        if (view != null) {
            RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();

            int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec,
                    getPaddingLeft() + getPaddingRight(), p.width);

            int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec,
                    getPaddingTop() + getPaddingBottom(), p.height);

            view.measure(childWidthSpec, childHeightSpec);
            measuredDimension[0] = view.getMeasuredWidth() + p.leftMargin + p.rightMargin;
            measuredDimension[1] = view.getMeasuredHeight() + p.bottomMargin + p.topMargin;
            recycler.recycleView(view);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:gaolhjy,项目名称:cniao5,代码行数:24,代码来源:FullyLinearLayoutManager.java

示例4: show

import android.view.View; //导入方法依赖的package包/类
public void show(View anchor) {
    if(!isShowing()) {
        this.blankWindow = new PopupWindow(this.blankView, anchor.getMeasuredWidth(), anchor.getMeasuredHeight());
        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

示例5: onLayout

import android.view.View; //导入方法依赖的package包/类
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int childLeft = 0;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View childView = getChildAt(i);
        if (childView.getVisibility() != View.GONE) {
            final int childWidth = childView.getMeasuredWidth();
            childView.layout(childLeft, 0, childLeft + childWidth,
                    childView.getMeasuredHeight());
            childLeft += childWidth;
        }
    }
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:15,代码来源:ScrollLayout.java

示例6: applyTrashMagnetismToBubble

import android.view.View; //导入方法依赖的package包/类
private void applyTrashMagnetismToBubble(BubbleLayout bubble) {
    View trashContentView = getTrashContent();
    int trashCenterX = (trashContentView.getLeft() + (trashContentView.getMeasuredWidth() / 2));
    int trashCenterY = (trashContentView.getTop() + (trashContentView.getMeasuredHeight() / 2));
    int x = (trashCenterX - (bubble.getMeasuredWidth() / 2));
    int y = (trashCenterY - (bubble.getMeasuredHeight() / 2));
    bubble.getViewParams().x = x;
    bubble.getViewParams().y = y;
    windowManager.updateViewLayout(bubble, bubble.getViewParams());
}
 
开发者ID:isacan,项目名称:Andzu,代码行数:11,代码来源:BubblesLayoutCoordinator.java

示例7: initPlaceHolderAndOverlay

import android.view.View; //导入方法依赖的package包/类
@Override
public void initPlaceHolderAndOverlay(@Nullable View overlayPlaceHolder, View rvContainer,
                                      View selectorContainer, int overlaySize) {
    if (overlayPlaceHolder != null) {
        int containerWidth = rvContainer.getMeasuredWidth();

        //make placeholder same height as a recyclerView
        overlayPlaceHolder.getLayoutParams().width = containerWidth;
        overlayPlaceHolder.requestLayout();

        selectorContainer.getLayoutParams().width = containerWidth + overlaySize;
        selectorContainer.requestLayout();

    }
}
 
开发者ID:sinhaDroid,项目名称:BlogBookApp,代码行数:16,代码来源:OrientationStateVertical.java

示例8: positionChild

import android.view.View; //导入方法依赖的package包/类
protected int positionChild(View child, int x, int y, int contentHeight, boolean reverse) {
    int childWidth = child.getMeasuredWidth();
    int childHeight = child.getMeasuredHeight();
    int childTop = y + ((contentHeight - childHeight) / 2);
    if (reverse) {
        child.layout(x - childWidth, childTop, x, childTop + childHeight);
    } else {
        child.layout(x, childTop, x + childWidth, childTop + childHeight);
    }
    return reverse ? -childWidth : childWidth;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:12,代码来源:AbsActionBarView.java

示例9: showHideWithAnimation

import android.view.View; //导入方法依赖的package包/类
private void showHideWithAnimation(final View view, boolean show, boolean center) {
    int cx = view.getMeasuredWidth();
    int cy = view.getMeasuredHeight();
    int w = view.getWidth();
    int h = view.getHeight();
    float r = (float) Math.sqrt(w * w + h * h);
    if (center) {
        cx = cx / 2;
        cy = cy / 2;
        r = Math.max(w / 2, h / 2);
    }
    Animator anim;
    if (show) {
        anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, r);
        view.setVisibility(View.VISIBLE);
    } else {
        anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, r, 0);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                view.setVisibility(View.INVISIBLE);
            }
        });
    }
    anim.start();
}
 
开发者ID:RanKKI,项目名称:PSNine,代码行数:28,代码来源:TopicActivity.java

示例10: getWidestView

import android.view.View; //导入方法依赖的package包/类
private static int getWidestView(Context context, Adapter adapter)
{
	int maxWidth = 0;
	View view = null;
	FrameLayout fakeParent = new FrameLayout(context);
	for (int i=0, count=adapter.getCount(); i<count; i++) {
		view = adapter.getView(i, view, fakeParent);
		view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
		int width = view.getMeasuredWidth();
		if (width > maxWidth) {
			maxWidth = width;
		}
	}
	return maxWidth;
}
 
开发者ID:ArtifexSoftware,项目名称:mupdf-android-viewer-nui,代码行数:16,代码来源:ProofActivity.java

示例11: removeNonVisibleChildren

import android.view.View; //导入方法依赖的package包/类
private void removeNonVisibleChildren(final int dx) {
    View child = getLeftmostChild();

    // Loop removing the leftmost child, until that child is on the screen
    while (child != null && child.getRight() + dx <= 0) {
        // The child is being completely removed so remove its width from the display offset and its divider if it has one.
        // To remove add the size of the child and its divider (if it has one) to the offset.
        // You need to add since its being removed from the left side, i.e. shifting the offset to the right.
        mDisplayOffset += isLastItemInAdapter(mLeftViewAdapterIndex) ? child.getMeasuredWidth() : mDividerWidth + child.getMeasuredWidth();

        // Add the removed view to the cache
        recycleView(mLeftViewAdapterIndex, child);

        // Actually remove the view
        removeViewInLayout(child);

        // Keep track of the adapter index of the left most child
        mLeftViewAdapterIndex++;

        // Get the new leftmost child
        child = getLeftmostChild();
    }

    child = getRightmostChild();

    // Loop removing the rightmost child, until that child is on the screen
    while (child != null && child.getLeft() + dx >= getWidth()) {
        recycleView(mRightViewAdapterIndex, child);
        removeViewInLayout(child);
        mRightViewAdapterIndex--;
        child = getRightmostChild();
    }
}
 
开发者ID:LanguidSheep,项目名称:sealtalk-android-master,代码行数:34,代码来源:HorizontalListView.java

示例12: onMeasure

import android.view.View; //导入方法依赖的package包/类
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
    int sizeWidth = MeasureSpec.getSize(widthMeasureSpec);
    int modeWidth = MeasureSpec.getMode(widthMeasureSpec);
    int sizeHeight = MeasureSpec.getSize(heightMeasureSpec);
    int modeHeight = MeasureSpec.getMode(heightMeasureSpec);

    // wrap_content
    int width = 0;
    int height = 0;

    int lineWidth = 0;
    int lineHeight = 0;

    int cCount = getChildCount();

    for (int i = 0; i < cCount; i++)
    {
        View child = getChildAt(i);
        if (child.getVisibility() == View.GONE)
        {
            if (i == cCount - 1)
            {
                width = Math.max(lineWidth, width);
                height += lineHeight;
            }
            continue;
        }
        measureChild(child, widthMeasureSpec, heightMeasureSpec);
        MarginLayoutParams lp = (MarginLayoutParams) child
                .getLayoutParams();

        int childWidth = child.getMeasuredWidth() + lp.leftMargin
                + lp.rightMargin;
        int childHeight = child.getMeasuredHeight() + lp.topMargin
                + lp.bottomMargin;

        if (lineWidth + childWidth > sizeWidth - getPaddingLeft() - getPaddingRight())
        {
            width = Math.max(width, lineWidth);
            lineWidth = childWidth;
            height += lineHeight;
            lineHeight = childHeight;
        } else
        {
            lineWidth += childWidth;
            lineHeight = Math.max(lineHeight, childHeight);
        }
        if (i == cCount - 1)
        {
            width = Math.max(lineWidth, width);
            height += lineHeight;
        }
    }
    setMeasuredDimension(
            //
            modeWidth == MeasureSpec.EXACTLY ? sizeWidth : width + getPaddingLeft() + getPaddingRight(),
            modeHeight == MeasureSpec.EXACTLY ? sizeHeight : height + getPaddingTop() + getPaddingBottom()//
    );

}
 
开发者ID:xieyangxuejun,项目名称:SearchLayout,代码行数:63,代码来源:FlowLayout.java

示例13: measureSize

import android.view.View; //导入方法依赖的package包/类
public static int[] measureSize(View v) {
    v.measure(MeasureSpec.makeMeasureSpec(0, 0), MeasureSpec.makeMeasureSpec(0, 0));
    int width = v.getMeasuredWidth();
    int height = v.getMeasuredHeight();
    return new int[]{width, height};
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:7,代码来源:UIsUtils.java

示例14: onMeasure

import android.view.View; //导入方法依赖的package包/类
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // Sets up mListPadding
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    int childWidth = 0;
    int childHeight = 0;

    mItemCount = mAdapter == null ? 0 : mAdapter.getCount();
    if (mItemCount > 0 && (widthMode == MeasureSpec.UNSPECIFIED ||
            heightMode == MeasureSpec.UNSPECIFIED)) {
        final View child = obtainView(0, mIsScrap);

        measureScrapChild(child, 0, widthMeasureSpec);

        childWidth = child.getMeasuredWidth();
        childHeight = child.getMeasuredHeight();

        if (recycleOnMeasure() && mRecycler.shouldRecycleViewType(
                ((LayoutParams) child.getLayoutParams()).viewType)) {
            mRecycler.addScrapView(child);
        }
    }

    if (widthMode == MeasureSpec.UNSPECIFIED) {
        widthSize = mListPadding.left + mListPadding.right + childWidth +
                getVerticalScrollbarWidth();
    }

    if (heightMode == MeasureSpec.UNSPECIFIED) {
        heightSize = mListPadding.top + mListPadding.bottom + childHeight +
                getVerticalFadingEdgeLength() * 2;
    }

    if (heightMode == MeasureSpec.AT_MOST) {
        // TODO: after first layout we should maybe start at the first visible position, not 0
        heightSize = measureHeightOfChildren(widthMeasureSpec, 0, NO_POSITION, heightSize, -1);
    }

    setMeasuredDimension(widthSize, heightSize);
    mWidthMeasureSpec = widthMeasureSpec;
}
 
开发者ID:Shmilyz,项目名称:Swap,代码行数:48,代码来源:PLA_ListView.java

示例15: layoutVertical

import android.view.View; //导入方法依赖的package包/类
void layoutVertical(int left, int top, int right, int bottom) {
    int childTop;
    int paddingLeft = getPaddingLeft();
    int width = right - left;
    int childRight = width - getPaddingRight();
    int childSpace = (width - paddingLeft) - getPaddingRight();
    int count = getVirtualChildCount();
    int minorGravity = this.mGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK;
    switch (this.mGravity & 112) {
        case 16:
            childTop = getPaddingTop() + (((bottom - top) - this.mTotalLength) / 2);
            break;
        case 80:
            childTop = ((getPaddingTop() + bottom) - top) - this.mTotalLength;
            break;
        default:
            childTop = getPaddingTop();
            break;
    }
    int i = 0;
    while (i < count) {
        View child = getVirtualChildAt(i);
        if (child == null) {
            childTop += measureNullChild(i);
        } else if (child.getVisibility() != 8) {
            int childLeft;
            int childWidth = child.getMeasuredWidth();
            int childHeight = child.getMeasuredHeight();
            LayoutParams lp = (LayoutParams) child.getLayoutParams();
            int gravity = lp.gravity;
            if (gravity < 0) {
                gravity = minorGravity;
            }
            switch (GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this)) & 7) {
                case 1:
                    childLeft = ((((childSpace - childWidth) / 2) + paddingLeft) + lp.leftMargin) - lp.rightMargin;
                    break;
                case 5:
                    childLeft = (childRight - childWidth) - lp.rightMargin;
                    break;
                default:
                    childLeft = paddingLeft + lp.leftMargin;
                    break;
            }
            if (hasDividerBeforeChildAt(i)) {
                childTop += this.mDividerHeight;
            }
            childTop += lp.topMargin;
            setChildFrame(child, childLeft, childTop + getLocationOffset(child), childWidth, childHeight);
            childTop += (lp.bottomMargin + childHeight) + getNextLocationOffset(child);
            i += getChildrenSkipCount(child, i);
        }
        i++;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:56,代码来源:LinearLayoutCompat.java


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