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

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

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

Button.getMeasuredHeight介绍

暂无

代码示例

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

final Button tv = (Button)findViewById(R.id.saveit);
 ViewTreeObserver vto = tv.getViewTreeObserver();
 vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
   public void onGlobalLayout() {
     ViewGroup.MarginLayoutParams vlp = (MarginLayoutParams) tv.getLayoutParams();
     int btnsize =tv.getMeasuredHeight()+vlp.topMargin;
     sizeit(btnsize);
     ViewTreeObserver obs = tv.getViewTreeObserver();
     obs.removeGlobalOnLayoutListener(this);
   }
 });

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

@Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    dragBtnHeight = dragBtn.getMeasuredHeight();
  }
}

代码示例来源: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: stackoverflow.com

final Button button1 = (Button) view.findViewById(R.id.button);
 final CollapseAnimator animator = new CollapseAnimator(topLayout);
 final ViewTreeObserver.OnGlobalLayoutListener listener = new ViewTreeObserver.OnGlobalLayoutListener() {
   @Override
   public void onGlobalLayout() {
     int mHeight = button1.getMeasuredHeight();
     KLog.i("onGlobalLayout() mHeight:" + mHeight);
     animator.setValues(mHeight*2, mHeight);
   }
 };
 button1.getViewTreeObserver().addOnGlobalLayoutListener(listener);
 button1.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
     view.post(new Runnable() {
       @Override
       public void run() {
         button1.getViewTreeObserver().removeOnGlobalLayoutListener(listener);
         animator.collapse();
       }
     });
   }
 });

代码示例来源: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: 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 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;
}

相关文章

Button类方法