当前位置: 首页>>代码示例>>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;未经允许,请勿转载。