예제 #1
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int paddingX = getPaddingLeft() + getPaddingRight();
    int paddingY = getPaddingTop() + getPaddingBottom();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      widthMeasureSpec =
          MeasureSpec.makeMeasureSpec(drawable.getIntrinsicWidth() + paddingX, MeasureSpec.EXACTLY);
      heightMeasureSpec =
          MeasureSpec.makeMeasureSpec(
              drawable.getIntrinsicHeight() + paddingY, MeasureSpec.EXACTLY);
      setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
    } else {
      setMeasuredDimension(
          drawable.getIntrinsicWidth() + paddingX, drawable.getIntrinsicHeight() + paddingY);
    }
  }
예제 #2
0
 private void adjustDrawablePadding() {
   if (drawable != null) {
     drawable.setBounds(
         0,
         0,
         drawable.getIntrinsicWidth() + getPaddingLeft() + getPaddingRight(),
         drawable.getIntrinsicHeight() + getPaddingTop() + getPaddingBottom());
   }
 }