com.zx.zxutils.util.ZXScreenUtil类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(4.2k)|赞(0)|评价(0)|浏览(101)

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

ZXScreenUtil介绍

[英]Created by Xiangb on 2017/5/2. 功能:屏幕相关工具类
[中]由湘博于2017年5月2日创建。功能:屏幕相关工具类

代码示例

代码示例来源:origin: StannyBing/ZXUtils

private static Rect calculateTapArea(float x, float y, float coefficient, Context context) {
  float focusAreaSize = 300;
  int areaSize = Float.valueOf(focusAreaSize * coefficient).intValue();
  int centerX = (int) (x / ZXScreenUtil.getScreenWidth() * 2000 - 1000);
  int centerY = (int) (y / ZXScreenUtil.getScreenHeight() * 2000 - 1000);
  int left = clamp(centerX - areaSize / 2, -1000, 1000);
  int top = clamp(centerY - areaSize / 2, -1000, 1000);
  RectF rectF = new RectF(left, top, left + areaSize, top + areaSize);
  return new Rect(Math.round(rectF.left), Math.round(rectF.top), Math.round(rectF.right), Math.round(rectF
      .bottom));
}

代码示例来源:origin: StannyBing/ZXUtils

switch (position) {
  case 0://获取屏幕的宽度
    btnbarView.printInfo("屏幕宽度:" + ZXScreenUtil.getScreenWidth());
    break;
  case 1://获取屏幕的高度
    btnbarView.printInfo("屏幕高度:" + ZXScreenUtil.getScreenHeight());
    break;
  case 2://设置屏幕为横屏
    ZXScreenUtil.setLandscape(this);
    break;
  case 3://设置屏幕为竖屏
    ZXScreenUtil.setPortrait(this);
    break;
  case 4://获取当前屏幕截图,包含状态栏
    Bitmap bitmap1 = ZXScreenUtil.getScreenShot(this);
    if (bitmap1 != null) {
      btnbarView.printInfo("截图成功,得到截图bitmap");
    Bitmap bitmap2 = ZXScreenUtil.getScreenShot(this);
    if (bitmap2 != null) {
      btnbarView.printInfo("截图成功,得到截图bitmap");

代码示例来源:origin: StannyBing/ZXUtils

public FoucsView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);
  this.size = ZXScreenUtil.getScreenWidth() / 3;
  mPaint = new Paint();
  mPaint.setAntiAlias(true);
  mPaint.setDither(true);
  mPaint.setColor(0xEE16AE16);
  mPaint.setStrokeWidth(4);
  mPaint.setStyle(Paint.Style.STROKE);
}

代码示例来源:origin: StannyBing/ZXUtils

/**
 * 用于处理上下的view出现右边超出屏幕的问题
 *
 * @param locationx
 * @return
 */
private int compareWithScreenWidthTopOrBottom(int locationx) {
  if (locationx + getMeasuredWidth() > ZXScreenUtil.getScreenWidth()) {//超出屏幕外了(右边)
    return ZXScreenUtil.getScreenWidth() - getMeasuredWidth();//此时刚好到屏幕右侧
  } else {
    return locationx < -20 ? -20 : locationx;
  }
}

代码示例来源:origin: StannyBing/ZXUtils

/**
 * 获取当前屏幕截图,包含状态栏
 *
 * @param activity
 * @return
 */
public static Bitmap getScreenShot(Activity activity) {
  View view = activity.getWindow().getDecorView();
  view.setDrawingCacheEnabled(true);
  view.buildDrawingCache();
  Bitmap bmp = view.getDrawingCache();
  int width = getScreenWidth();
  int height = getScreenHeight();
  Bitmap bp = null;
  bp = Bitmap.createBitmap(bmp, 0, 0, width, height);
  view.destroyDrawingCache();
  return bp;
}

代码示例来源:origin: StannyBing/ZXUtils

/**
 * 用于处理左右的view出现左右超出屏幕的问题(重新定义popupwindow的宽度)
 *
 * @param locationx
 * @param type
 * @return
 */
private int compareWithScreenWidthLeftOrRight(int locationx, int type) {
  if (type == 0) {//left
    if (locationx < 0) {//左侧超出屏幕外了
      setWidth(locationx + getMeasuredWidth());
      return 0;
    }
  } else {//right
    if (locationx + getMeasuredWidth() > ZXScreenUtil.getScreenWidth()) {//右侧超出屏幕外了
      setWidth(ZXScreenUtil.getScreenWidth() - locationx);
    }
  }
  return locationx;
}

代码示例来源:origin: StannyBing/ZXUtils

/**
 * 获取当前屏幕截图,不包含状态栏
 *
 * @param activity
 * @return
 */
public static Bitmap getScreenShotWithoutStatusBar(Activity activity) {
  View view = activity.getWindow().getDecorView();
  view.setDrawingCacheEnabled(true);
  view.buildDrawingCache();
  Bitmap bmp = view.getDrawingCache();
  Rect frame = new Rect();
  activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
  int statusBarHeight = frame.top;
  int width = getScreenWidth();
  int height = getScreenHeight();
  Bitmap bp = null;
  bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height
      - statusBarHeight);
  view.destroyDrawingCache();
  return bp;
}

代码示例来源:origin: StannyBing/ZXUtils

@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent motionEvent) {
  if (bgVisible) {
    rv.requestDisallowInterceptTouchEvent(true);
  } else if ((ZXScreenUtil.getScreenWidth() > touchedX + 150)
      && (motionEvent.getRawX() - touchedX < 0)) {
    rv.requestDisallowInterceptTouchEvent(true);
  } else {
    rv.requestDisallowInterceptTouchEvent(false);
  }
  return handleTouchEvent(motionEvent);
}

代码示例来源:origin: StannyBing/ZXUtils

private void initData() {
  layout_width = ZXScreenUtil.getScreenWidth();
  //缩放梯度
  zoomGradient = (int) (layout_width / 16f);
  ZXLogUtil.logi("zoom = " + zoomGradient);
  machine = new CameraMachine(getContext(), this, this);
}

相关文章