android.view.View.getMeasuredWidth()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中android.view.View.getMeasuredWidth()方法的一些代码示例,展示了View.getMeasuredWidth()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。View.getMeasuredWidth()方法的具体详情如下:
包路径:android.view.View
类名称:View
方法名:getMeasuredWidth

View.getMeasuredWidth介绍

暂无

代码示例

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Sets the layout resource for a custom MarkerView.
 *
 * @param layoutResource
 */
private void setupLayoutResource(int layoutResource) {
  View inflated = LayoutInflater.from(getContext()).inflate(layoutResource, this);
  inflated.setLayoutParams(new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
  inflated.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
  // measure(getWidth(), getHeight());
  inflated.layout(0, 0, inflated.getMeasuredWidth(), inflated.getMeasuredHeight());
}

代码示例来源:origin: chentao0707/SimplifyReader

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
  mInLayout = true;
  if (mContentView != null)
    mContentView.layout(mContentLeft, mContentTop,
        mContentLeft + mContentView.getMeasuredWidth(),
        mContentTop + mContentView.getMeasuredHeight());
  mInLayout = false;
}

代码示例来源:origin: aa112901/remusic

public static int getWidth(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.getMeasuredWidth());
}

代码示例来源:origin: stackoverflow.com

Display display = getWindowManager().getDefaultDisplay();
View view = findViewById(R.id.YOUR_VIEW_ID);
view.measure(display.getWidth(), display.getHeight());

view.getMeasuredWidth(); // view width
view.getMeasuredHeight(); //view height

代码示例来源:origin: daimajia/AndroidSwipeLayout

protected Rect getRelativePosition(View child) {
  View t = child;
  Rect r = new Rect(t.getLeft(), t.getTop(), 0, 0);
  while (t.getParent() != null && t != getRootView()) {
    t = (View) t.getParent();
    if (t == this) break;
    r.left += t.getLeft();
    r.top += t.getTop();
  }
  r.right = r.left + child.getMeasuredWidth();
  r.bottom = r.top + child.getMeasuredHeight();
  return r;
}

代码示例来源:origin: rey5137/material

@Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    int childLeft = 0;
    int childTop = 0;
    int childRight = right - left;
    int childBottom = bottom - top;
    if(mIsRtl)
      for(int i = 0, count = getChildCount(); i < count; i++){
        View child = getChildAt(i);
        child.layout(childRight - child.getMeasuredWidth(), childTop, childRight, childBottom);
        childRight -= child.getMeasuredWidth();
      }
    else
      for(int i = 0, count = getChildCount(); i < count; i++){
        View child = getChildAt(i);
        child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(), childBottom);
        childLeft += child.getMeasuredWidth();
      }
  }
}

代码示例来源:origin: facebook/litho

/**
 * Measure and layout a component view.
 *
 * @param view The component view to measure and layout
 */
public static void measureAndLayout(View view) {
 view.measure(makeMeasureSpec(1000, EXACTLY), makeMeasureSpec(0, UNSPECIFIED));
 view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
}

代码示例来源:origin: square/leakcanary

@Override protected void onLayout(boolean changed, int l, int t, int r, int b) {
  int width = getMeasuredWidth();
  int connectorRight = rowMargins + connector.getMeasuredWidth();
  connector.layout(rowMargins, 0, connectorRight, connector.getMeasuredHeight());

  moreButton.layout(width - rowMargins - moreSize, moreMarginTop, width - rowMargins,
    moreMarginTop + moreSize);

  int titleLeft = connectorRight + rowMargins;
  int titleBottom = titleMarginTop + title.getMeasuredHeight();
  title.layout(titleLeft, titleMarginTop, titleLeft + title.getMeasuredWidth(), titleBottom);

  if (details.getVisibility() != GONE) {
   details.layout(titleLeft, titleBottom, width - rowMargins,
     titleBottom + details.getMeasuredHeight());
  }
 }
}

代码示例来源:origin: stackoverflow.com

int height = heightSpecSize - handle.getMeasuredHeight() - mTopOffset;
content.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, heightSpecMode));
heightSpecSize = handle.getMeasuredHeight() + mTopOffset + content.getMeasuredHeight();
widthSpecSize = content.getMeasuredWidth();
if (handle.getMeasuredWidth() > widthSpecSize) widthSpecSize = handle.getMeasuredWidth();
int width = widthSpecSize - handle.getMeasuredWidth() - mTopOffset;
getContent().measure(MeasureSpec.makeMeasureSpec(width, widthSpecMode), heightMeasureSpec);
widthSpecSize = handle.getMeasuredWidth() + mTopOffset + content.getMeasuredWidth();
heightSpecSize = content.getMeasuredHeight();
if (handle.getMeasuredHeight() > heightSpecSize) heightSpecSize = handle.getMeasuredHeight();

代码示例来源:origin: scwang90/SmartRefreshLayout

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  final View thisView = this;
  final int width = thisView.getMeasuredWidth();
  final int height = thisView.getMeasuredHeight();
  mScaleX = 1f * width / WIDTH;
  mScaleY = 1f * (mViewportHeight > 0 ? mViewportHeight : height) / HEIGHT;
  updateMountainPath(mMoveFactor, height);
  updateTreePath(mMoveFactor, true);
}

代码示例来源:origin: aa112901/remusic

public static int getWidth(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.getMeasuredWidth());
}

代码示例来源:origin: tyzlmjj/PagerBottomTabStrip

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
  final int count = getChildCount();
  final int width = right - left;
  final int height = bottom - top;
  //只支持top、bottom的padding
  final int padding_top = getPaddingTop();
  final int padding_bottom = getPaddingBottom();
  int used = 0;
  for (int i = 0; i < count; i++) {
    final View child = getChildAt(i);
    if (child.getVisibility() == GONE) {
      continue;
    }
    if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL) {
      child.layout(width - used - child.getMeasuredWidth(), padding_top, width - used, height - padding_bottom);
    } else {
      child.layout(used, padding_top, child.getMeasuredWidth() + used, height - padding_bottom);
    }
    used += child.getMeasuredWidth();
  }
}

代码示例来源:origin: stackoverflow.com

public static Bitmap getBitmapFromView(View view) {
  view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
  Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),
      Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(bitmap);
  view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
  view.draw(canvas);
  return bitmap;
}

代码示例来源:origin: scwang90/SmartRefreshLayout

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
  final View thisView = this;
  final View imageView = mImageView;
  final View dropView = mWaterDropView;
  final int measuredWidth = thisView.getMeasuredWidth();
  final int widthWaterDrop = dropView.getMeasuredWidth();
  final int heightWaterDrop = dropView.getMeasuredHeight();
  final int leftWaterDrop = measuredWidth / 2 - widthWaterDrop / 2;
  final int topWaterDrop = 0;
  dropView.layout(leftWaterDrop, topWaterDrop, leftWaterDrop + widthWaterDrop, topWaterDrop + heightWaterDrop);
  final int widthImage = imageView.getMeasuredWidth();
  final int heightImage = imageView.getMeasuredHeight();
  final int leftImage = measuredWidth / 2 - widthImage / 2;
  int topImage = widthWaterDrop / 2 - widthImage / 2;
  if (topImage + heightImage > dropView.getBottom() - (widthWaterDrop - widthImage) / 2) {
    topImage = dropView.getBottom() - (widthWaterDrop - widthImage) / 2 - heightImage;
  }
  imageView.layout(leftImage, topImage, leftImage + widthImage, topImage + heightImage);
}
//</editor-fold>

代码示例来源:origin: scwang90/SmartRefreshLayout

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  final View imageView = mImageView;
  final View dropView = mWaterDropView;
  LayoutParams lpImage = (LayoutParams) imageView.getLayoutParams();
  imageView.measure(
      makeMeasureSpec(lpImage.width, EXACTLY),
      makeMeasureSpec(lpImage.height, EXACTLY)
  );
  dropView.measure(
      makeMeasureSpec(getSize(widthMeasureSpec), AT_MOST),
      heightMeasureSpec
  );
  int maxWidth = Math.max(imageView.getMeasuredWidth(), dropView.getMeasuredWidth());
  int maxHeight = Math.max(imageView.getMeasuredHeight(), dropView.getMeasuredHeight());
  super.setMeasuredDimension(View.resolveSize(maxWidth, widthMeasureSpec), View.resolveSize(maxHeight, heightMeasureSpec));
}

代码示例来源:origin: scwang90/SmartRefreshLayout

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  final View thisView = this;
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  if (Build.VERSION.SDK_INT < 21) {
    super.setMeasuredDimension(
        thisView.getMeasuredWidth() + mShadowRadius * 2,
        thisView.getMeasuredHeight() + mShadowRadius * 2);
  }
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

/**
 * 获取控件的宽
 * @param view
 * @return
 */
public static int getWidgetWidth(View view){
  int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
  int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
  view.measure(w, h);//先度量  
  int width = view.getMeasuredWidth();  
  return width;
}
/**

代码示例来源:origin: xinghongfei/LookLook

private Bitmap convertViewToBitmap(View view) {
  view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
      View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
  view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
  view.buildDrawingCache();
  Bitmap bitmap = view.getDrawingCache();
  return bitmap;
}

代码示例来源:origin: Rukey7/MvpApp

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
  mInLayout = true;
  if (mContentView != null) {
    mContentView.layout(mContentLeft, mContentTop,
        mContentLeft + mContentView.getMeasuredWidth(),
        mContentTop + mContentView.getMeasuredHeight());
  }
  mInLayout = false;
}

代码示例来源:origin: stackoverflow.com

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);

相关文章

微信公众号

最新文章

更多

View类方法