本文整理汇总了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 {
}
}
示例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);
}
示例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();
}
}
示例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;
}
}
示例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;
}
}
}
示例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());
}
示例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();
}
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
}
示例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()//
);
}
示例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};
}
示例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;
}
示例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++;
}
}