android.widget.Button.getMeasuredWidth()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(133)

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

Button.getMeasuredWidth介绍

暂无

代码示例

代码示例来源:origin: hiphonezhu/Android-Demos

/**
 * 更新位置
 */
public void restorePosition() {
  // 读取保存的位置
  float x = sp.getFloat(KEY_FLOATING_X, -1);
  float y = sp.getFloat(KEY_FLOATING_Y, -1);
  if (x == -1 && y == -1) { // 初始位置
    x = getMeasuredWidth() - floatingBtn.getMeasuredWidth();
    y = getMeasuredHeight() * 2 / 3;
  }
  floatingBtn.layout((int)x, (int)y,
      (int)x + floatingBtn.getMeasuredWidth(), (int)y + floatingBtn.getMeasuredHeight());
}

代码示例来源:origin: behindeye/WxPhoneNumberHelper

public static Bitmap getBitmap(Context context, String paramString,
    int bgsid, int textsize, int textcolor) {
  Button localButton = new Button(context);
  localButton.setBackgroundResource(bgsid);
  localButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, textsize);
  localButton.setText(paramString);
  localButton.setTextColor(textcolor);
  localButton.setDrawingCacheEnabled(true);
  localButton.measure(View.MeasureSpec.makeMeasureSpec(0, 0),
      View.MeasureSpec.makeMeasureSpec(0, 0));
  localButton.layout(0, 0, localButton.getMeasuredWidth(),
      localButton.getMeasuredHeight());
  localButton.buildDrawingCache();
  return Bitmap.createBitmap(localButton.getDrawingCache());
}

代码示例来源:origin: r17171709/android_demo

public View a() {
  ArrayList<CalculatorBean> beanArrayList=new ArrayList<>();
  int[] location=new int[2];
  btn_showcase.getLocationOnScreen(location);
  CalculatorBean bean=new CalculatorBean();
  bean.setmCircleCenterX(location[0]+btn_showcase.getMeasuredWidth()/2);
  bean.setmCircleCenterY(location[1]+btn_showcase.getMeasuredHeight()/2);
  bean.setmCircleRadius(150);
  bean.setmFocusShape(FocusShape.CIRCLE);
  beanArrayList.add(bean);
  View view= LayoutInflater.from(MainActivity.this).inflate(R.layout.view1, null, false);
  ShowCaseImageView image_showcase= view.findViewById(R.id.image_showcase);
  image_showcase.setmAnimationEnabled(false);
  image_showcase.setmCalculatorBeen(beanArrayList);
  image_showcase.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      showCaseView.dismiss();
    }
  });
  return view;
}

代码示例来源:origin: ahmclishihao/gankS

/**
 * 弹出一个popupwindow
 */
public static void getPopupWindow(View anchor, Context context, String text, final View.OnClickListener cl) {
  Button button = new Button(context);
  button.setBackgroundResource(R.drawable.selector_btn_save);
  button.setText(text);
  button.setTextColor(Color.BLACK);
  button.setPadding(10, 5, 10, 5);
  button.setOnClickListener(cl);
  button.measure(0, 0);
  final PopupWindow popupWindow = new PopupWindow(button, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
  popupWindow.setBackgroundDrawable(new BitmapDrawable());
  // 设置背景和focusable使得可以点击消失
  popupWindow.setFocusable(true);
  if (Build.VERSION.SDK_INT >= 21)
    popupWindow.setElevation(5);
  popupWindow.showAsDropDown(anchor, anchor.getMeasuredWidth() / 2 - button.getMeasuredWidth() / 2, -anchor.getMeasuredHeight() / 2 - button.getMeasuredHeight() / 2);
  // 回调 提供的监听
  button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      // 两个View.OnClickListener不冲突
      cl.onClick(v);
      popupWindow.dismiss();
    }
  });
}

代码示例来源:origin: r17171709/android_demo

public View b() {
    ArrayList<CalculatorBean> beanArrayList=new ArrayList<>();

    int[] location1=new int[2];
    btn1_showcase.getLocationOnScreen(location1);
    CalculatorBean bean1=new CalculatorBean();
    bean1.setmCircleCenterX(location1[0]+btn1_showcase.getMeasuredWidth()/2);
    bean1.setmCircleCenterY(location1[1]+btn1_showcase.getMeasuredHeight()/2);
    bean1.setmCircleRadius(20);
    bean1.setmFocusHeight(btn1_showcase.getMeasuredHeight());
    bean1.setmFocusWidth(btn1_showcase.getMeasuredWidth());
    bean1.setmFocusShape(FocusShape.ROUNDED_RECTANGLE);
    beanArrayList.add(bean1);

    View view= LayoutInflater.from(MainActivity.this).inflate(R.layout.view1, null, false);
    ShowCaseImageView image_showcase= view.findViewById(R.id.image_showcase);
    image_showcase.setmAnimationEnabled(false);
    image_showcase.setmCalculatorBeen(beanArrayList);
    image_showcase.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        showCaseView.dismiss();
      }
    });

    return view;
  }
}

代码示例来源:origin: HuanHaiLiuXin/SweetTips

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  if (mMaxWidth > 0 && getMeasuredWidth() > mMaxWidth) {
    widthMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxWidth, MeasureSpec.EXACTLY);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  }
  final int multiLineVPadding = getResources().getDimensionPixelSize(
      R.dimen.design_snackbar_padding_vertical_2lines);
  final int singleLineVPadding = getResources().getDimensionPixelSize(
      R.dimen.design_snackbar_padding_vertical);
  final boolean isMultiLine = mMessageView.getLayout().getLineCount() > 1;
  boolean remeasure = false;
  if (isMultiLine && mMaxInlineActionWidth > 0
      && mActionView.getMeasuredWidth() > mMaxInlineActionWidth) {
    if (updateViewsWithinLayout(VERTICAL, multiLineVPadding,
        multiLineVPadding - singleLineVPadding)) {
      remeasure = true;
    }
  } else {
    final int messagePadding = isMultiLine ? multiLineVPadding : singleLineVPadding;
    if (updateViewsWithinLayout(HORIZONTAL, messagePadding, messagePadding)) {
      remeasure = true;
    }
  }
  if (remeasure) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  }
}

代码示例来源:origin: the-pig-of-jungle/SmartShow

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  if (mMaxWidth > 0 && getMeasuredWidth() > mMaxWidth) {
    widthMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxWidth, MeasureSpec.EXACTLY);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  }
  final int multiLineVPadding = getResources().getDimensionPixelSize(
      android.support.design.R.dimen.design_snackbar_padding_vertical_2lines);
  final int singleLineVPadding = getResources().getDimensionPixelSize(
      android.support.design.R.dimen.design_snackbar_padding_vertical);
  final boolean isMultiLine = mMessageView.getLayout().getLineCount() > 1;
  boolean remeasure = false;
  if (isMultiLine && mMaxInlineActionWidth > 0
      && mActionView.getMeasuredWidth() > mMaxInlineActionWidth) {
    if (updateViewsWithinLayout(VERTICAL, multiLineVPadding,
        multiLineVPadding - singleLineVPadding)) {
      remeasure = true;
    }
  } else {
    final int messagePadding = isMultiLine ? multiLineVPadding : singleLineVPadding;
    if (updateViewsWithinLayout(HORIZONTAL, messagePadding, messagePadding)) {
      remeasure = true;
    }
  }
  if (remeasure) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  }
}

代码示例来源:origin: the-pig-of-jungle/smart-show

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  if (mMaxWidth > 0 && getMeasuredWidth() > mMaxWidth) {
    widthMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxWidth, MeasureSpec.EXACTLY);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  }
  final int multiLineVPadding = getResources().getDimensionPixelSize(
      android.support.design.R.dimen.design_snackbar_padding_vertical_2lines);
  final int singleLineVPadding = getResources().getDimensionPixelSize(
      android.support.design.R.dimen.design_snackbar_padding_vertical);
  final boolean isMultiLine = mMessageView.getLayout().getLineCount() > 1;
  boolean remeasure = false;
  if (isMultiLine && mMaxInlineActionWidth > 0
      && mActionView.getMeasuredWidth() > mMaxInlineActionWidth) {
    if (updateViewsWithinLayout(VERTICAL, multiLineVPadding,
        multiLineVPadding - singleLineVPadding)) {
      remeasure = true;
    }
  } else {
    final int messagePadding = isMultiLine ? multiLineVPadding : singleLineVPadding;
    if (updateViewsWithinLayout(HORIZONTAL, messagePadding, messagePadding)) {
      remeasure = true;
    }
  }
  if (remeasure) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  }
}

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

mButtonWidth = mButton.getMeasuredWidth();

相关文章

Button类方法