當前位置: 首頁>>代碼示例>>Java>>正文


Java TextPaint.ascent方法代碼示例

本文整理匯總了Java中android.text.TextPaint.ascent方法的典型用法代碼示例。如果您正苦於以下問題:Java TextPaint.ascent方法的具體用法?Java TextPaint.ascent怎麽用?Java TextPaint.ascent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.text.TextPaint的用法示例。


在下文中一共展示了TextPaint.ascent方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initPaint

import android.text.TextPaint; //導入方法依賴的package包/類
/**
 * define paints
 */
private void initPaint() {
    // round rectangle paint
    mStrokePaint = new Paint();
    mStrokePaint.setColor(mSelectedColor);
    mStrokePaint.setStyle(Paint.Style.STROKE);
    mStrokePaint.setAntiAlias(true);
    mStrokePaint.setStrokeWidth(mStrokeWidth);
    // selected paint
    mFillPaint = new Paint();
    mFillPaint.setColor(mSelectedColor);
    mFillPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mStrokePaint.setAntiAlias(true);
    // selected text paint
    mSelectedTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mSelectedTextPaint.setTextSize(mTextSize);
    mSelectedTextPaint.setColor(mSelectedColor);
    mStrokePaint.setAntiAlias(true);
    // unselected text paint
    mUnselectedTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mUnselectedTextPaint.setTextSize(mTextSize);
    mUnselectedTextPaint.setColor(0xffffffff);
    mStrokePaint.setAntiAlias(true);
    mTextHeightOffset = -(mSelectedTextPaint.ascent() + mSelectedTextPaint.descent()) * 0.5f;
}
 
開發者ID:DSM-DMS,項目名稱:DMS,代碼行數:28,代碼來源:SwitchMultiButton.java

示例2: findClosestRow

import android.text.TextPaint; //導入方法依賴的package包/類
/**
 * Returns the row (0 indexed) closest to previouslyFocusedRect or center if null.
 */
private int findClosestRow(@Nullable Rect previouslyFocusedRect) {
    if (previouslyFocusedRect == null) {
        return 3;
    } else {
        int centerY = previouslyFocusedRect.centerY();

        final TextPaint p = mDayPaint;
        final int headerHeight = mMonthHeight + mDayOfWeekHeight;
        final int rowHeight = mDayHeight;

        // Text is vertically centered within the row height.
        final float halfLineHeight = (p.ascent() + p.descent()) / 2f;
        final int rowCenter = headerHeight + rowHeight / 2;

        centerY -= rowCenter - halfLineHeight;
        int row = Math.round(centerY / (float) rowHeight);
        final int maxDay = findDayOffset() + mDaysInMonth;
        final int maxRows = (maxDay / DAYS_IN_WEEK) - ((maxDay % DAYS_IN_WEEK == 0) ? 1 : 0);

        row = mathConstrain(row, 0, maxRows);
        return row;
    }
}
 
開發者ID:Gericop,項目名稱:DateTimePicker,代碼行數:27,代碼來源:SimpleMonthView.java

示例3: drawDaysOfWeek

import android.text.TextPaint; //導入方法依賴的package包/類
private void drawDaysOfWeek(Canvas canvas) {
    final TextPaint p = mDayOfWeekPaint;
    final int headerHeight = mMonthHeight;
    final int rowHeight = mDayOfWeekHeight;
    final int colWidth = mCellWidth;

    // Text is vertically centered within the day of week height.
    final float halfLineHeight = (p.ascent() + p.descent()) / 2f;
    final int rowCenter = headerHeight + rowHeight / 2;

    for (int col = 0; col < DAYS_IN_WEEK; col++) {
        final int colCenter = colWidth * col + colWidth / 2;
        final int colCenterRtl;
        if (isLayoutRtl()) {
            colCenterRtl = mPaddedWidth - colCenter;
        } else {
            colCenterRtl = colCenter;
        }

        final String label = mDayOfWeekLabels[col];
        canvas.drawText(label, colCenterRtl, rowCenter - halfLineHeight, p);
    }
}
 
開發者ID:Gericop,項目名稱:DateTimePicker,代碼行數:24,代碼來源:SimpleMonthView.java

示例4: initDrawable

import android.text.TextPaint; //導入方法依賴的package包/類
/**
         * 根據文本大小, 自動設置圖片的高度
         */
        public static Drawable initDrawable(Context context, @DrawableRes int resourceId, float textSize) {
            Drawable drawable = ContextCompat.getDrawable(context, resourceId);
            int height = drawable.getIntrinsicHeight();
            int width = drawable.getIntrinsicWidth();

            TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
            textPaint.setTextSize(textSize);
            float textHeight = textPaint.descent() - textPaint.ascent(); //(int) RTextPaint.getTextHeight(textPaint);

//            if (textHeight > height) {
//                int offset = textHeight - height + textPaint.getFontMetricsInt().descent / 2;
//                InsetDrawable insetDrawable = new InsetDrawable(drawable, 0, offset, 0, 0);
//                insetDrawable.setBounds(0, 0, width, textHeight);
//                return insetDrawable;
//            } else {
//                drawable.setBounds(0, 0, width, height);
//                return drawable;
//            }

            //drawable.setBounds(0, 0, width, (int) Math.max(height, textHeight));
            drawable.setBounds(0, 0, width, (int) -textPaint.ascent()/*(int) Math.max(height, textHeight)*/);
            return drawable;
        }
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:27,代碼來源:RExTextView.java

示例5: applySuperScriptStyle

import android.text.TextPaint; //導入方法依賴的package包/類
public void applySuperScriptStyle(@NonNull TextPaint paint) {
    final float ratio;
    if (Float.compare(scriptTextSizeRatio, .0F) == 0) {
        ratio = SCRIPT_DEF_TEXT_SIZE_RATIO;
    } else {
        ratio = scriptTextSizeRatio;
    }
    paint.setTextSize(paint.getTextSize() * ratio);
    paint.baselineShift += (int) (paint.ascent() / 2);
}
 
開發者ID:noties,項目名稱:Markwon,代碼行數:11,代碼來源:SpannableTheme.java

示例6: applySubScriptStyle

import android.text.TextPaint; //導入方法依賴的package包/類
public void applySubScriptStyle(@NonNull TextPaint paint) {
    final float ratio;
    if (Float.compare(scriptTextSizeRatio, .0F) == 0) {
        ratio = SCRIPT_DEF_TEXT_SIZE_RATIO;
    } else {
        ratio = scriptTextSizeRatio;
    }
    paint.setTextSize(paint.getTextSize() * ratio);
    paint.baselineShift -= (int) (paint.ascent() / 2);
}
 
開發者ID:noties,項目名稱:Markwon,代碼行數:11,代碼來源:SpannableTheme.java

示例7: JuzView

import android.text.TextPaint; //導入方法依賴的package包/類
public JuzView(Context context, int type, String overlayText) {
  final Resources resources = context.getResources();
  final int circleColor = ContextCompat.getColor(context, R.color.accent_color);
  final int circleBackground = ContextCompat.getColor(context, R.color.accent_color_dark);

  mCirclePaint = new Paint();
  mCirclePaint.setStyle(Paint.Style.FILL);
  mCirclePaint.setColor(circleColor);
  mCirclePaint.setAntiAlias(true);

  mCircleBackgroundPaint = new Paint();
  mCircleBackgroundPaint.setStyle(Paint.Style.FILL);
  mCircleBackgroundPaint.setColor(circleBackground);
  mCircleBackgroundPaint.setAntiAlias(true);

  mOverlayText = overlayText;
  if (!TextUtils.isEmpty(mOverlayText)) {
    final int textColor = ContextCompat.getColor(context, R.color.header_background);
    final int textSize =
        resources.getDimensionPixelSize(R.dimen.juz_overlay_text_size);
    mOverlayTextPaint = new TextPaint();
    mOverlayTextPaint.setAntiAlias(true);
    mOverlayTextPaint.setColor(textColor);
    mOverlayTextPaint.setTextSize(textSize);
    mOverlayTextPaint.setTextAlign(Paint.Align.CENTER);

    final float textHeight =
        mOverlayTextPaint.descent() - mOverlayTextPaint.ascent();
    mTextOffset = (textHeight / 2) - mOverlayTextPaint.descent();
  }

  final int percentage;
  switch (type) {
    case TYPE_JUZ:
      percentage = 100;
      break;
    case TYPE_THREE_QUARTERS:
      percentage = 75;
      break;
    case TYPE_HALF:
      percentage = 50;
      break;
    case TYPE_QUARTER:
      percentage = 25;
      break;
    default:
      percentage = 0;
  }
  mPercentage = percentage;
}
 
開發者ID:Elias33,項目名稱:Quran,代碼行數:51,代碼來源:JuzView.java

示例8: updateDrawState

import android.text.TextPaint; //導入方法依賴的package包/類
public void updateDrawState(TextPaint paint) {
    paint.baselineShift += (int) (((double) paint.ascent()) * this.ratio);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:4,代碼來源:SuperscriptSpanAdjuster.java

示例9: updateMeasureState

import android.text.TextPaint; //導入方法依賴的package包/類
public void updateMeasureState(TextPaint paint) {
    paint.baselineShift += (int) (((double) paint.ascent()) * this.ratio);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:4,代碼來源:SuperscriptSpanAdjuster.java

示例10: initPaint

import android.text.TextPaint; //導入方法依賴的package包/類
private void initPaint() {
    mPathEffect = new DashPathEffect(new float[]{dp2, dp2}, 1);
    mGradeAxisPaint = new Paint();
    mGradeAxisPaint.reset();
    mGradeAxisPaint.setStyle(Paint.Style.STROKE);
    mGradeAxisPaint.setStrokeWidth(1);
    mGradeAxisPaint.setColor(isDebug ? Color.parseColor("#f00000") : Color.parseColor("#16ffffff"));
    mGradeAxisPaint.setAntiAlias(true);
    mGradeAxisPaint.setPathEffect(mPathEffect);

    mChartPaint = new Paint();
    mChartPaint.setStyle(Paint.Style.FILL);
    mChartPaint.setStrokeWidth(4);
    mChartPaint.setAntiAlias(true);

    mChartTestLinePaint = new Paint();
    mChartTestLinePaint.setStyle(Paint.Style.STROKE);
    mChartTestLinePaint.setStrokeWidth(dp2px(1));
    mChartTestLinePaint.setColor(Color.parseColor("#DF6A56"));
    mChartTestLinePaint.setAntiAlias(true);
    mChartTestLinePaint.setAlpha(0);
    if (isDebug) {
        mChartTestLinePaint.setAlpha(255);
    }

    mChartIndicatorPaint = new Paint();
    mChartIndicatorPaint.setStyle(Paint.Style.STROKE);
    mChartIndicatorPaint.setStrokeWidth(dp2px(1));

    mWhitePaint = new Paint();
    mWhitePaint.setStyle(Paint.Style.FILL);
    mWhitePaint.setColor(Color.parseColor("#ffffff"));

    mWhiteTextPaint = new TextPaint();
    mWhiteTextPaint.setColor(Color.parseColor("#ffffff"));
    mWhiteTextPaint.setTextSize(dp2px(11));
    mWhiteTextPaint.setAntiAlias(true);

    mWhiteTextPaintHeight = mWhiteTextPaint.descent() + mWhiteTextPaint.ascent();

    mDarkTextPaint = new TextPaint(mWhiteTextPaint);
    mDarkTextPaint.setAlpha(127);

    mPathIndicatorLine = new Path();
    mPathIndicatorLine.setFillType(Path.FillType.WINDING);

    mPathGradLine = new Path();
    mRectIndicator = new RectF();
}
 
開發者ID:maoruibin,項目名稱:TrendChartView,代碼行數:50,代碼來源:TrendChartView.java

示例11: drawDays

import android.text.TextPaint; //導入方法依賴的package包/類
/**
 * Draws the month days.
 */
private void drawDays(Canvas canvas) {
    final TextPaint p = mDayPaint;
    final int headerHeight = mMonthHeight + mDayOfWeekHeight;
    final int rowHeight = mDayHeight;
    final int colWidth = mCellWidth;

    // Text is vertically centered within the row height.
    final float halfLineHeight = (p.ascent() + p.descent()) / 2f;
    int rowCenter = headerHeight + rowHeight / 2;

    for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) {
        final int colCenter = colWidth * col + colWidth / 2;
        final int colCenterRtl;
        if (isLayoutRtl()) {
            colCenterRtl = mPaddedWidth - colCenter;
        } else {
            colCenterRtl = colCenter;
        }

        int stateMask = 0;

        final boolean isDayEnabled = isDayEnabled(day);
        if (isDayEnabled) {
            stateMask |= StateSet.VIEW_STATE_ENABLED;
        }

        final boolean isDayActivated = mActivatedDay == day;
        final boolean isDayHighlighted = mHighlightedDay == day;
        if (isDayActivated) {
            stateMask |= StateSet.VIEW_STATE_ACTIVATED;

            // Adjust the circle to be centered on the row.
            final Paint paint = isDayHighlighted ? mDayHighlightSelectorPaint :
                    mDaySelectorPaint;
            canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, paint);
        } else if (isDayHighlighted) {
            stateMask |= StateSet.VIEW_STATE_PRESSED;

            if (isDayEnabled) {
                // Adjust the circle to be centered on the row.
                canvas.drawCircle(colCenterRtl, rowCenter,
                        mDaySelectorRadius, mDayHighlightPaint);
            }
        }

        final boolean isDayToday = mToday == day;
        final int dayTextColor;
        if (isDayToday && !isDayActivated) {
            dayTextColor = mDaySelectorPaint.getColor();
        } else {
            final int[] stateSet = StateSet.get(stateMask);
            dayTextColor = mDayTextColor.getColorForState(stateSet, 0);
        }
        p.setColor(dayTextColor);

        canvas.drawText(mDayFormatter.format(day), colCenterRtl, rowCenter - halfLineHeight, p);

        col++;

        if (col == DAYS_IN_WEEK) {
            col = 0;
            rowCenter += rowHeight;
        }
    }
}
 
開發者ID:Gericop,項目名稱:DateTimePicker,代碼行數:69,代碼來源:SimpleMonthView.java


注:本文中的android.text.TextPaint.ascent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。