当前位置: 首页>>代码示例>>Java>>正文


Java Paint.descent方法代码示例

本文整理汇总了Java中android.graphics.Paint.descent方法的典型用法代码示例。如果您正苦于以下问题:Java Paint.descent方法的具体用法?Java Paint.descent怎么用?Java Paint.descent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.Paint的用法示例。


在下文中一共展示了Paint.descent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: drawText

import android.graphics.Paint; //导入方法依赖的package包/类
private void drawText(Canvas canvas) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(getResources().getDimension(R.dimen.item_circle_text_size));

    // 四边为整数
    Rect areaRect = new Rect(0, 0, canvas.getWidth(), canvas.getHeight());
    // 四边为浮点数
    RectF bounds = new RectF(areaRect);
    bounds.right = paint.measureText(text, 0, text.length());
    // 基准线以下的距离(正数) - 基准线以上的距离(负数)
    bounds.bottom = paint.descent() - paint.ascent();
    bounds.left += (areaRect.width() - bounds.right) / 2.0f;
    bounds.top += (areaRect.height() - bounds.bottom) / 2.0f;

    paint.setColor(Color.WHITE);
    canvas.drawText(text, bounds.left, bounds.top - paint.ascent(), paint);
}
 
开发者ID:yuhodev,项目名称:login,代码行数:18,代码来源:RoundedView.java

示例2: textAsBitmap

import android.graphics.Paint; //导入方法依赖的package包/类
/** @return a bitmap with text.*/
private static Bitmap textAsBitmap(String text, float textSize, int textColor) {

    Paint paint = new Paint();
    paint.setTextSize(textSize);
    paint.setColor(textColor);
    paint.setTextAlign(Paint.Align.LEFT);

    int width = (int) (paint.measureText(text) + 0.5f); // round
    float baseline = (int) (-paint.ascent() + 0.5f); // ascent() is negative
    int height = (int) (baseline + paint.descent() + 0.5f);

    Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(image);
    canvas.drawText(text, 0, baseline, paint);

    return image;
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:20,代码来源:ImageUtils.java

示例3: layoutText

import android.graphics.Paint; //导入方法依赖的package包/类
private void layoutText() {
    Paint paint = getPaint();
    if(mTextSize != 0f) paint.setTextSize(mTextSize);
    float textWidth = paint.measureText(getText().toString());
    float width = getWidth() - getPaddingLeft() - getPaddingRight();
    float textSize = getTextSize();
    if(textWidth > width) {
        paint.setTextSize(textSize * width / textWidth);
        mTextX = getPaddingLeft();
        mTextSize = textSize;
    }
    else {
        mTextX = (getWidth() - textWidth) / 2;
    }
    mTextY = (getHeight() - paint.ascent() - paint.descent()) / 2;
    if(mHintPaint != null) mHintPaint.setTextSize(paint.getTextSize() * 0.8f);
}
 
开发者ID:gigabytedevelopers,项目名称:CalcMate,代码行数:18,代码来源:ColorButton.java

示例4: getLabelBitmap

import android.graphics.Paint; //导入方法依赖的package包/类
/**
 *
 * @param name name of the zone
 * @param zoneLabelOptions appearance options for the zone label marker
 * @return Bitmap with the zone label
 */
private Bitmap getLabelBitmap(String name, ZoneLabelOptions zoneLabelOptions){
    Paint zonesLabelPaint = new Paint();
    zonesLabelPaint.setTextSize(zoneLabelOptions.getLabelSize());
    zonesLabelPaint.setColor(zoneLabelOptions.getLabelColor());
    zonesLabelPaint.setTextAlign(Paint.Align.LEFT);
    float zoneLabelBaseline = -zonesLabelPaint.ascent();

    int width = (int) (zonesLabelPaint.measureText(name) + 0.5f); // round
    int height = (int) (zoneLabelBaseline + zonesLabelPaint.descent() + 0.5f);

    Bitmap zoneLabelBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas zoneLabelCanvas = new Canvas(zoneLabelBitmap);
    zoneLabelCanvas.drawText(name, 0, zoneLabelBaseline, zonesLabelPaint);
    return zoneLabelBitmap;
}
 
开发者ID:Ubudu,项目名称:GoogleMapsLayout-Android,代码行数:22,代码来源:MapLayout.java

示例5: calcBounds

import android.graphics.Paint; //导入方法依赖的package包/类
/**
 * Calculate the bounds for a view's title
 *
 * @param index
 * @param paint
 * @return
 */
private Rect calcBounds(int index, Paint paint) {
    //Calculate the text bounds
    Rect bounds = new Rect();
    CharSequence title = getTitle(index);
    bounds.right = (int) paint.measureText(title, 0, title.length());
    bounds.bottom = (int) (paint.descent() - paint.ascent());
    return bounds;
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:16,代码来源:TitlePageIndicator.java

示例6: createRoundIconWithText

import android.graphics.Paint; //导入方法依赖的package包/类
static Bitmap createRoundIconWithText(Context context, String letter) {

        //calculate dimensions
        //-1 to take into account the shadow layer
        int w = (int) context.getResources().getDimension(android.R.dimen.app_icon_size);
        int h = (int) context.getResources().getDimension(android.R.dimen.app_icon_size);
        int r = w / 2 - 1;

        //create bitmap
        Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);

        //draw a circle of the same dimensions
        Canvas canvas = new Canvas(b);
        Paint paint = new Paint();
        int color = ContextCompat.getColor(context, getRandom(SolidWallpaperUtils.material_colors));
        paint.setColor(color);

        final int SHADOW_COLOR = 0x80000000;
        paint.setShadowLayer(0.5f, 1, 1, SHADOW_COLOR);
        paint.setAntiAlias(true);
        canvas.drawCircle(r, r, r, paint);

        Paint textPaint = new Paint();
        textPaint.setColor(Utilities.getComplementaryColor(color));
        textPaint.setTextAlign(Paint.Align.CENTER);
        textPaint.setTextSize(w / 2);

        textPaint.setAntiAlias(true);
        textPaint.setTypeface(Typeface.SANS_SERIF);
        int xPos = (canvas.getWidth() / 2);
        int yPos = (int) ((canvas.getHeight() / 2) - ((textPaint.descent() + textPaint.ascent()) / 2));

        canvas.drawText(letter, xPos, yPos, textPaint);

        return b;
    }
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:37,代码来源:RoundedContact.java

示例7: drawIconGlyph

import android.graphics.Paint; //导入方法依赖的package包/类
private static void drawIconGlyph(Context context, String iconChar, int size, Canvas canvas, int color) {
    Paint textPaint = new Paint();
    textPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    textPaint.setTextAlign(Paint.Align.CENTER);
    textPaint.setColor(color);
    textPaint.setTextSize(size);
    textPaint.setTypeface(Typeface.createFromAsset(context.getResources().getAssets(), "SalesforceDesignSystemIcons.ttf"));
    float y = (size / 2.0f) - ((textPaint.descent() + textPaint.ascent()) / 2.0f);
    canvas.drawText(iconChar, (size / 2.0f), y, textPaint);
}
 
开发者ID:salesforce-ux,项目名称:design-system-android,代码行数:11,代码来源:Icons.java

示例8: calcBounds

import android.graphics.Paint; //导入方法依赖的package包/类
private Rect calcBounds(int index, Paint paint) {
    Rect bounds = new Rect();
    CharSequence title = getTitle(index);
    bounds.right = (int) paint.measureText(title, 0, title.length());
    bounds.bottom = (int) (paint.descent() - paint.ascent());
    return bounds;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:8,代码来源:TitlePageIndicator.java

示例9: CandidateView

import android.graphics.Paint; //导入方法依赖的package包/类
/**
 * Construct a CandidateView for showing suggested words for completion.
 * @param context
 * @param attrs
 */
public CandidateView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mSelectionHighlight = context.getResources().getDrawable(
            R.drawable.list_selector_background_pressed);

    LayoutInflater inflate =
        (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    Resources res = context.getResources();
    mPreviewPopup = new PopupWindow(context);
    mPreviewText = (TextView) inflate.inflate(R.layout.candidate_preview, null);
    mPreviewPopup.setWindowLayoutMode(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    mPreviewPopup.setContentView(mPreviewText);
    mPreviewPopup.setBackgroundDrawable(null);
    mPreviewPopup.setAnimationStyle(R.style.KeyPreviewAnimation);
    mColorNormal = res.getColor(R.color.candidate_normal);
    mColorRecommended = res.getColor(R.color.candidate_recommended);
    mColorOther = res.getColor(R.color.candidate_other);
    mDivider = res.getDrawable(R.drawable.keyboard_suggest_strip_divider);
    mAddToDictionaryHint = res.getString(R.string.hint_add_to_dictionary);

    mPaint = new Paint();
    mPaint.setColor(mColorNormal);
    mPaint.setAntiAlias(true);
    mPaint.setTextSize(mPreviewText.getTextSize());
    mPaint.setStrokeWidth(0);
    mPaint.setTextAlign(Align.CENTER);
    mDescent = (int) mPaint.descent();
    mMinTouchableWidth = (int)res.getDimension(R.dimen.candidate_min_touchable_width);
    
    mGestureDetector = new GestureDetector(
            new CandidateStripGestureListener(mMinTouchableWidth));
    setWillNotDraw(false);
    setHorizontalScrollBarEnabled(false);
    setVerticalScrollBarEnabled(false);
    scrollTo(0, getScrollY());
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:43,代码来源:CandidateView.java

示例10: calculatePositions

import android.graphics.Paint; //导入方法依赖的package包/类
/**
 * Using the trigonometric Unit Circle, calculate the positions that the text will need to be
 * drawn at based on the specified circle radius. Place the values in the textGridHeights and
 * textGridWidths parameters.
 */
private static void calculatePositions(Paint paint, float radius, float xCenter, float yCenter,
        float textSize, float[] x, float[] y) {
    // Adjust yCenter to account for the text's baseline.
    paint.setTextSize(textSize);
    yCenter -= (paint.descent() + paint.ascent()) / 2;

    for (int i = 0; i < NUM_POSITIONS; i++) {
        x[i] = xCenter - radius * COS_30[i];
        y[i] = yCenter - radius * SIN_30[i];
    }
}
 
开发者ID:Gericop,项目名称:DateTimePicker,代码行数:17,代码来源:RadialTimePickerView.java

示例11: drawLanguageOnSpacebar

import android.graphics.Paint; //导入方法依赖的package包/类
private void drawLanguageOnSpacebar(final Key key, final Canvas canvas, final Paint paint) {
    final Keyboard keyboard = getKeyboard();
    if (keyboard == null) {
        return;
    }
    final int width = key.getWidth();
    final int height = key.getHeight();
    paint.setTextAlign(Align.CENTER);
    paint.setTypeface(Typeface.DEFAULT);
    paint.setTextSize(mLanguageOnSpacebarTextSize);
    final String language = layoutLanguageOnSpacebar(paint, keyboard.mId.mSubtype, width);
    // Draw language text with shadow
    final float descent = paint.descent();
    final float textHeight = -paint.ascent() + descent;
    final float baseline = height / 2 + textHeight / 2;
    if (mLanguageOnSpacebarTextShadowRadius > 0.0f) {
        paint.setShadowLayer(mLanguageOnSpacebarTextShadowRadius, 0, 0,
                mLanguageOnSpacebarTextShadowColor);
    } else {
        paint.clearShadowLayer();
    }
    paint.setColor(mLanguageOnSpacebarTextColor);
    paint.setAlpha(mLanguageOnSpacebarAnimAlpha);
    canvas.drawText(language, width / 2, baseline - descent, paint);
    paint.clearShadowLayer();
    paint.setTextScaleX(1.0f);
}
 
开发者ID:rkkr,项目名称:simple-keyboard,代码行数:28,代码来源:MainKeyboardView.java

示例12: getRoundedLetterImage

import android.graphics.Paint; //导入方法依赖的package包/类
/**
 * Creates a rounded square of a certain color with
 * a character imprinted in white on it.
 *
 * @param character the character to write on the image.
 * @param width     the width of the final image.
 * @param height    the height of the final image.
 * @param color     the background color of the rounded square.
 * @return a valid bitmap of a rounded square with a character on it.
 */
@NonNull
public static Bitmap getRoundedLetterImage(@NonNull Character character, int width, int height, int color) {
    Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(image);
    Paint paint = new Paint();
    paint.setColor(color);
    Typeface boldText = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD);
    paint.setTypeface(boldText);
    paint.setTextSize(Utils.dpToPx(14));
    paint.setAntiAlias(true);
    paint.setTextAlign(Paint.Align.CENTER);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));

    int radius = Utils.dpToPx(2);

    RectF outer = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
    canvas.drawRoundRect(outer, radius, radius, paint);

    int xPos = (canvas.getWidth() / 2);
    int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2));

    paint.setColor(Color.WHITE);
    canvas.drawText(character.toString(), xPos, yPos, paint);

    return image;
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:37,代码来源:DrawableUtils.java

示例13: drawSelection

import android.graphics.Paint; //导入方法依赖的package包/类
private void drawSelection(Canvas canvas) {
	if (isSelection) {
		int[] startPosition = mCode.getPosition(Math.min(selectionStart, selectionEnd));
		int[] endPosition = mCode.getPosition(Math.max(selectionStart, selectionEnd));
		Paint paint = new Paint(mPaint);
		paint.setColor(textSelectionBackgroundColor);
		float height = paint.descent() - paint.ascent();
		if (startPosition[1] == endPosition[1]) {
			LineSource line = mCode.getLineSource(startPosition[1]);
			float startX = paint.measureText(line.subSequence(0, startPosition[0]).toString());
			float endX = paint.measureText(line.subSequence(0, endPosition[0]).toString());
			canvas.drawRect(-xScroll + startX, -yScroll + height * startPosition[1], -xScroll + endX, -yScroll + height * (startPosition[1] + 1), paint);
		} else {
			LineSource ls1 = mCode.getLineSource(startPosition[1]);
			canvas.drawRect(-xScroll + paint.measureText(ls1.subSequence(0, startPosition[0]).toString()), -yScroll + height * startPosition[1], -xScroll + paint.measureText(ls1.toString()), -yScroll + height * (startPosition[1] + 1), paint);
			LineSource ls2 = mCode.getLineSource(endPosition[1]);
			canvas.drawRect(-xScroll, -yScroll + height * endPosition[1], -xScroll + paint.measureText(ls2.subSequence(0, endPosition[0]).toString()), -yScroll + height * (endPosition[1] + 1), paint);
			int len = endPosition[1] - startPosition[1];
			int offset = startPosition[1];
			int h = getHeight();
			for (int i=1;i < len;i++) {
				float top = -yScroll + height * (offset + i);
				float bottom = -yScroll + height * (offset + i + 1);
				if (top > h || bottom < 0) {
					continue;
				}
				canvas.drawRect(-xScroll, top, -xScroll + paint.measureText(mCode.getLineSource(offset + i).toString()), bottom, paint);
			}
		}
	}
}
 
开发者ID:chushi0,项目名称:CodeView,代码行数:32,代码来源:CodeView.java

示例14: getRoundedNumberImage

import android.graphics.Paint; //导入方法依赖的package包/类
@NonNull
public static Bitmap getRoundedNumberImage(int number, int width, int height, int color, int thickness) {
    String text;

    if (number > 99) {
        text = "\u221E";
    } else {
        text = String.valueOf(number);
    }

    Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(image);
    Paint paint = new Paint();
    paint.setColor(color);
    Typeface boldText = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD);
    paint.setTypeface(boldText);
    paint.setTextSize(Utils.dpToPx(14));
    paint.setAntiAlias(true);
    paint.setTextAlign(Paint.Align.CENTER);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));

    int radius = Utils.dpToPx(2);

    RectF outer = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
    canvas.drawRoundRect(outer, radius, radius, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

    radius--;
    RectF inner = new RectF(thickness, thickness, canvas.getWidth() - thickness, canvas.getHeight() - thickness);
    canvas.drawRoundRect(inner, radius, radius, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));

    int xPos = (canvas.getWidth() / 2);
    int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2));

    canvas.drawText(String.valueOf(text), xPos, yPos, paint);

    return image;
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:42,代码来源:DrawableUtils.java

示例15: b

import android.graphics.Paint; //导入方法依赖的package包/类
public int b(Paint paint) {
    return (int) (paint.descent() - paint.ascent());
}
 
开发者ID:xieyangxuejun,项目名称:CommentView,代码行数:4,代码来源:TextCell.java


注:本文中的android.graphics.Paint.descent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。