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

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

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

View.getWidth介绍

暂无

代码示例

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

@Override
public void draw(Canvas canvas, Paint paint) {
  final View thisView = CircleImageView.this;
  final int viewWidth = thisView.getWidth();
  final int viewHeight = thisView.getHeight();
  canvas.drawCircle(viewWidth / 2, viewHeight / 2, viewWidth / 2, mShadowPaint);
  canvas.drawCircle(viewWidth / 2, viewHeight / 2, viewWidth / 2 - mShadowRadius, paint);
}

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

public Bitmap screenShot(View view) {
  Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),
      view.getHeight(), Config.ARGB_8888);
  Canvas canvas = new Canvas(bitmap);
  view.draw(canvas);
  return bitmap;
}

代码示例来源:origin: naman14/Timber

static float calculateMaxRadius(View view) {
  float widthSquared = view.getWidth() * view.getWidth();
  float heightSquared = view.getHeight() * view.getHeight();
  float radius = (float) Math.sqrt(widthSquared + heightSquared) / 2;
  return radius;
}

代码示例来源:origin: Yalantis/Side-Menu.Android

@Override
  public void run() {
    Bitmap bitmap = Bitmap.createBitmap(containerView.getWidth(),
        containerView.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    containerView.draw(canvas);
    ContentFragment.this.bitmap = bitmap;
  }
};

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

@Nullable
@Override
public Object getElementToHighlightAtPosition(View element, int x, int y, Rect bounds) {
 bounds.set(0, 0, element.getWidth(), element.getHeight());
 return element;
}

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

public Bitmap viewToBitmap(View view) {
  Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(bitmap);
  view.draw(canvas);
  return bitmap;
}

代码示例来源:origin: bumptech/glide

@Override
 public boolean onPreDraw() {
  if (actualDimensions == null) {
   actualDimensions = new int[] { view.getWidth(), view.getHeight() };
  }
  view.getViewTreeObserver().removeOnPreDrawListener(this);
  return true;
 }
});

代码示例来源:origin: CameraKit/blurkit-android

private Bitmap getBitmapForView(View src) {
  Bitmap bitmap = Bitmap.createBitmap(
      src.getWidth(),
      src.getHeight(),
      Bitmap.Config.ARGB_8888
  );
  Canvas canvas = new Canvas(bitmap);
  src.draw(canvas);
  return bitmap;
}

代码示例来源:origin: nickbutcher/plaid

private void captureValues(TransitionValues transitionValues) {
    final View view = transitionValues.view;
    if (view == null || view.getWidth() <= 0 || view.getHeight() <= 0) return;

    transitionValues.values.put(PROP_BOUNDS, new Rect(view.getLeft(), view.getTop(),
        view.getRight(), view.getBottom()));
  }
}

代码示例来源:origin: naman14/Timber

@Override
public void captureStartValues(TransitionValues transitionValues) {
  final View view = transitionValues.view;
  if (view.getWidth() <= 0 || view.getHeight() <= 0) {
    return;
  }
  captureValues(transitionValues);
  Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),
      Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(bitmap);
  view.draw(canvas);
  transitionValues.values.put(PROPERTY_IMAGE, bitmap);
}

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

private boolean isViewContains(View view, int rx, int ry) {
  int[] l = new int[2];
  view.getLocationOnScreen(l);
  int x = l[0];
  int y = l[1];
  int w = view.getWidth();
  int h = view.getHeight();

  if (rx < x || rx > x + w || ry < y || ry > y + h) {
    return false;
  }
  return true;
}

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

public static Bitmap getBitmapFromView(View view) {
   //Define a bitmap with the same size as the view
   Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),Bitmap.Config.ARGB_8888);
   //Bind a canvas to it
   Canvas canvas = new Canvas(returnedBitmap);
   //Get the view's background
   Drawable bgDrawable =view.getBackground();
   if (bgDrawable!=null) 
     //has background drawable, then draw it on the canvas
     bgDrawable.draw(canvas);
   else 
     //does not have background drawable, then draw white background on the canvas
     canvas.drawColor(Color.WHITE);
   // draw the view on the canvas
   view.draw(canvas);
   //return the bitmap
   return returnedBitmap;
 }

代码示例来源:origin: naman14/Timber

static int calculateMinRadius(View view) {
  return Math.min(view.getWidth() / 2, view.getHeight() / 2);
}

代码示例来源:origin: facebook/facebook-android-sdk

@Override
  public String call() {
    View view = this.rootView.get();
    if (view == null || view.getWidth() == 0 || view.getHeight() == 0) {
      return "";
    }
    Bitmap bitmap = Bitmap.createBitmap(
        view.getWidth(), view.getHeight(), Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas(bitmap);
    view.draw(canvas);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    // TODO: T25009391, Support better screenshot image quality by using file attachment.
    bitmap.compress(Bitmap.CompressFormat.JPEG, 10, outputStream);
    return Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
  }
}

代码示例来源:origin: andkulikov/Transitions-Everywhere

private void captureValues(TransitionValues transitionValues) {
  View view = transitionValues.view;
  view.getLocationOnScreen(mTempLoc);
  int left = mTempLoc[0];
  int top = mTempLoc[1];
  int right = left + view.getWidth();
  int bottom = top + view.getHeight();
  transitionValues.values.put(PROPNAME_SCREEN_BOUNDS, new Rect(left, top, right, bottom));
}

代码示例来源:origin: wangdan/AisenWeiBo

private void setNameBitmap() {
  if (layName == null)
    return;
  layNameBitmap = Bitmap.createBitmap(layName.getWidth(), layName.getHeight(), Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(layNameBitmap);
  layName.draw(canvas);
  layName.setVisibility(View.INVISIBLE);
  layNameMatrix = new Matrix();
}

代码示例来源:origin: andkulikov/Transitions-Everywhere

private static double calculateMaxDistance(View sceneRoot, int focalX, int focalY) {
  int maxX = Math.max(focalX, sceneRoot.getWidth() - focalX);
  int maxY = Math.max(focalY, sceneRoot.getHeight() - focalY);
  return Math.hypot(maxX, maxY);
}

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

public static Bitmap getBitmapFromView(View view) {
  Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(returnedBitmap);
  Drawable bgDrawable =view.getBackground();
  if (bgDrawable!=null) 
    bgDrawable.draw(canvas);
  else 
    canvas.drawColor(Color.WHITE);
  view.draw(canvas);
  return returnedBitmap;
}

代码示例来源:origin: nickbutcher/plaid

@Override
public boolean animateAdd(RecyclerView.ViewHolder holder) {
  holder.itemView.setAlpha(0f);
  switch (slideFromEdge) {
    case Gravity.LEFT:
      holder.itemView.setTranslationX(-holder.itemView.getWidth() / 3);
      break;
    case Gravity.TOP:
      holder.itemView.setTranslationY(-holder.itemView.getHeight() / 3);
      break;
    case Gravity.RIGHT:
      holder.itemView.setTranslationX(holder.itemView.getWidth() / 3);
      break;
    default: // Gravity.BOTTOM
      holder.itemView.setTranslationY(holder.itemView.getHeight() / 3);
  }
  pendingAdds.add(holder);
  return true;
}

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

@Override
protected void dispatchDraw(Canvas canvas) {
  super.dispatchDraw(canvas);
  final View thisView = this;
  if (thisView.isInEditMode()) {//这段代码在运行时不会执行,只会在Studio编辑预览时运行,不用在意性能问题
    int d = DensityUtil.dp2px(5);
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(0xcccccccc);
    paint.setStrokeWidth(DensityUtil.dp2px(1));
    paint.setPathEffect(new DashPathEffect(new float[]{d, d, d, d}, 1));
    canvas.drawRect(d, d, thisView.getWidth() - d, thisView.getBottom() - d, paint);
    TextView textView = new TextView(thisView.getContext());
    textView.setText(thisView.getResources().getString(R.string.srl_component_falsify, getClass().getSimpleName(), DensityUtil.px2dp(thisView.getHeight())));
    textView.setTextColor(0xcccccccc);
    textView.setGravity(Gravity.CENTER);
    //noinspection UnnecessaryLocalVariable
    View view = textView;
    view.measure(makeMeasureSpec(thisView.getWidth(), EXACTLY), makeMeasureSpec(thisView.getHeight(), EXACTLY));
    view.layout(0, 0, thisView.getWidth(), thisView.getHeight());
    view.draw(canvas);
  }
}

相关文章

微信公众号

最新文章

更多

View类方法