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


Java Paint.ascent方法代碼示例

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


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

示例1: getEmoji

import android.graphics.Paint; //導入方法依賴的package包/類
private static Bitmap getEmoji(
        Context context, String emoji, @DimenRes int sizeResId, @DimenRes int insetResId) {
    if (context == null || TextUtils.isEmpty(emoji)) {
        return null;
    }
    int size = context.getResources().getDimensionPixelSize(sizeResId);
    int inset = context.getResources().getDimensionPixelSize(insetResId);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL);
    paint.setTextAlign(Paint.Align.LEFT);
    paint.setTextSize(size);
    float baseline = -paint.ascent();
    int width = (int) (paint.measureText(emoji) + 0.5f);
    int height = (int) (baseline + paint.descent() + 0.5f);
    Bitmap bitmap = Bitmap.createBitmap(width + inset * 2, height + inset * 2, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawText(emoji, inset, baseline + inset, paint);
    return bitmap;
}
 
開發者ID:nicholasrout,項目名稱:shortstories,代碼行數:20,代碼來源:BitmapUtil.java

示例2: drawLineNumber

import android.graphics.Paint; //導入方法依賴的package包/類
private void drawLineNumber(Canvas canvas) {
	Paint paint = new Paint(mPaint);
	int count = mCode.getLineCount();
	float height = paint.descent() - paint.ascent();
	float baseline = height * 3 / 4;
	paint.setColor(lineNumberColor);
	for (int i=0;i < count;i++) {
		float x = -xScroll;
		float y = -yScroll + height * i;
		if (y > getHeight() || y < -height) {
			continue;
		}
		canvas.drawText(String.valueOf(i + 1), x, y + baseline, paint);
	}
	float leftPadding = paint.measureText(String.valueOf(count));
	canvas.drawLine(-xScroll + leftPadding, -yScroll, -xScroll + leftPadding, -yScroll + height * count, paint);
}
 
開發者ID:chushi0,項目名稱:CodeView,代碼行數:18,代碼來源:CodeView.java

示例3: 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:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:TitlePageIndicator.java

示例4: 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:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:28,代碼來源:MainKeyboardView.java

示例5: textAsBitmap

import android.graphics.Paint; //導入方法依賴的package包/類
public Bitmap textAsBitmap(String text, float textSize, int textColor) {
    Paint paint = new Paint(ANTI_ALIAS_FLAG);
    paint.setTextSize(textSize);
    paint.setColor(textColor);
    paint.setTextAlign(Paint.Align.LEFT);
    float baseline = -paint.ascent(); // ascent() is negative
    int width = (int) (paint.measureText(text) + 0.5f); // round
    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:KrishAmal,項目名稱:NavAR,代碼行數:14,代碼來源:PoiBrowserActivity.java

示例6: 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

示例7: bitMapFromText

import android.graphics.Paint; //導入方法依賴的package包/類
private Bitmap bitMapFromText(String text, float textSize, int textColor) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(textSize);
    paint.setColor(textColor);
    paint.setTextAlign(Paint.Align.LEFT);
    float baseLine = -paint.ascent();
    int width = (int) (paint.measureText(text) + 0.0f);
    int height = (int) (baseLine + paint.measureText(text) + 0.0f);

    Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(image);
    canvas.drawText(text, 0, baseLine, paint);
    return image;
}
 
開發者ID:aliumujib,項目名稱:Orin,代碼行數:15,代碼來源:IndexLayoutManager.java

示例8: 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

示例9: textAsBitmap

import android.graphics.Paint; //導入方法依賴的package包/類
/**
 * Return text As bitmap
 *
 * @param text
 * @param textSize
 * @param textColor
 * @return
 */
public static Bitmap textAsBitmap(String text, float textSize, int textColor) {
    Paint paint = new Paint(ANTI_ALIAS_FLAG);
    paint.setTextSize(textSize); //text size
    paint.setColor(textColor); //text color
    paint.setTextAlign(Paint.Align.LEFT); //align center
    float baseline = -paint.ascent(); // ascent() is negative
    int width = (int) (paint.measureText(text) + 0.0f); // round
    int height = (int) (baseline + paint.descent() + 0.0f);
    Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(image);
    canvas.drawText(text, 0, baseline, paint); //draw text
    return image;
}
 
開發者ID:RajneeshSingh007,項目名稱:MusicX-music-player,代碼行數:22,代碼來源:Helper.java

示例10: 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,代碼行數:12,代碼來源:Icons.java

示例11: 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

示例12: 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

示例13: draw

import android.graphics.Paint; //導入方法依賴的package包/類
public void draw(Canvas canvas) {

        if (mState == STATE_HIDDEN)
            return;

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mListView.getContext());
        if(prefs.getBoolean("alphaindex",true)){
           show();
        }else hide();

        // mAlphaRate determines the rate of opacity
        Paint indexbarPaint = new Paint();
        indexbarPaint.setColor(Color.BLACK);
        indexbarPaint.setAlpha((int) (64 * mAlphaRate));
        indexbarPaint.setAntiAlias(true);
        canvas.drawRoundRect(mIndexbarRect, 5 * mDensity, 5 * mDensity, indexbarPaint);

        if (mSections != null && mSections.length > 0) {
            // Preview is shown when mCurrentSection is set
            if (mCurrentSection >= 0) {
                /*Paint previewPaint = new Paint();
                previewPaint.setColor(Color.BLACK);
                previewPaint.setAlpha(96);
                previewPaint.setAntiAlias(true);
                previewPaint.setShadowLayer(3, 0, 0, Color.argb(64, 0, 0, 0));

                Paint previewTextPaint = new Paint();
                previewTextPaint.setColor(Color.WHITE);
                previewTextPaint.setAntiAlias(true);
                previewTextPaint.setTextSize(50 * mScaledDensity);

                float previewTextWidth = previewTextPaint.measureText(mSections[mCurrentSection]);
                float previewSize = 2 * mPreviewPadding + previewTextPaint.descent() - previewTextPaint.ascent();
                RectF previewRect = new RectF((mListViewWidth - previewSize) / 2
                        , (mListViewHeight - previewSize) / 2
                        , (mListViewWidth - previewSize) / 2 + previewSize
                        , (mListViewHeight - previewSize) / 2 + previewSize);

                canvas.drawRoundRect(previewRect, 5 * mDensity, 5 * mDensity, previewPaint);
                canvas.drawText(mSections[mCurrentSection], previewRect.left + (previewSize - previewTextWidth) / 2 - 1
                        , previewRect.top + mPreviewPadding - previewTextPaint.ascent() + 1, previewTextPaint);*/
            }

            Paint indexPaint = new Paint();
            indexPaint.setColor(Color.WHITE);
            indexPaint.setAlpha((int) (255 * mAlphaRate));
            indexPaint.setAntiAlias(true);
            indexPaint.setTextSize(12 * mScaledDensity);

            float sectionHeight = (mIndexbarRect.height() - 2 * mIndexbarMargin) / mSections.length;
            float paddingTop = (sectionHeight - (indexPaint.descent() - indexPaint.ascent())) / 2;
            for (int i = 0; i < mSections.length; i++) {
                float paddingLeft = (mIndexbarWidth - indexPaint.measureText(mSections[i])) / 2;
                canvas.drawText(mSections[i], mIndexbarRect.left + paddingLeft
                        , mIndexbarRect.top + mIndexbarMargin + sectionHeight * i + paddingTop - indexPaint.ascent(), indexPaint);
            }
        }
    }
 
開發者ID:jathak,項目名稱:sflauncher,代碼行數:59,代碼來源:IndexScroller.java

示例14: draw

import android.graphics.Paint; //導入方法依賴的package包/類
public void draw(Canvas canvas) {
	if (mState == STATE_HIDDEN || invisible)
		return;
	
	// mAlphaRate determines the rate of opacity
	Paint indexbarPaint = new Paint();
	indexbarPaint.setColor(Color.BLACK);
	indexbarPaint.setAlpha((int) (64 * mAlphaRate));
	indexbarPaint.setAntiAlias(true);
	canvas.drawRoundRect(mIndexbarRect, 5 * mDensity, 5 * mDensity, indexbarPaint);
	
	if (mSections != null && mSections.length > 0) {
		// Preview is shown when mCurrentSection is set
		if (mCurrentSection >= 0) {
			Paint previewPaint = new Paint();
			previewPaint.setColor(Color.BLACK);
			previewPaint.setAlpha(96);
			previewPaint.setAntiAlias(true);
			previewPaint.setShadowLayer(3, 0, 0, Color.argb(64, 0, 0, 0));
			
			Paint previewTextPaint = new Paint();
			previewTextPaint.setColor(Color.WHITE);
			previewTextPaint.setAntiAlias(true);
			previewTextPaint.setTextSize(50 * mScaledDensity);
			if(defaultTypeface!=null) {
				previewTextPaint.setTypeface(defaultTypeface);
			}

			float previewTextWidth = previewTextPaint.measureText(mSections[mCurrentSection]);
			float previewSize = 2 * mPreviewPadding + previewTextPaint.descent() - previewTextPaint.ascent();
			RectF previewRect = new RectF((mListViewWidth - previewSize) / 2
					, (mListViewHeight - previewSize) / 2
					, (mListViewWidth - previewSize) / 2 + previewSize
					, (mListViewHeight - previewSize) / 2 + previewSize);
			
			canvas.drawRoundRect(previewRect, 5 * mDensity, 5 * mDensity, previewPaint);
			canvas.drawText(mSections[mCurrentSection], previewRect.left + (previewSize - previewTextWidth) / 2 - 1
					, previewRect.top + mPreviewPadding - previewTextPaint.ascent() + 1, previewTextPaint);
		}
		
		Paint indexPaint = new Paint();
		indexPaint.setColor(Color.WHITE);
		indexPaint.setAlpha((int) (255 * mAlphaRate));
		indexPaint.setAntiAlias(true);
		indexPaint.setTextSize(12 * mScaledDensity);
		if(defaultTypeface!=null) {
			indexPaint.setTypeface(defaultTypeface);
		}

		float sectionHeight = (mIndexbarRect.height() - 2 * mIndexbarMargin) / mSections.length;
		float paddingTop = (sectionHeight - (indexPaint.descent() - indexPaint.ascent())) / 2;
		for (int i = 0; i < mSections.length; i++) {
			float paddingLeft = (mIndexbarWidth - indexPaint.measureText(mSections[i])) / 2;
			canvas.drawText(mSections[i], mIndexbarRect.left + paddingLeft
					, mIndexbarRect.top + mIndexbarMargin + sectionHeight * i + paddingTop - indexPaint.ascent(), indexPaint);
		}
	}
}
 
開發者ID:sylversky,項目名稱:IndexableListView,代碼行數:59,代碼來源:IndexScroller.java

示例15: drawTextCentered

import android.graphics.Paint; //導入方法依賴的package包/類
private void drawTextCentered(String text, float x, float y, Paint paint, Canvas canvas) {
    //float xPos = x - (paint.measureText(text)/2f);
    float yPos = (y - ((paint.descent() + paint.ascent()) / 2f));
    canvas.drawText(text, x, yPos, paint);
}
 
開發者ID:Pygmalion69,項目名稱:Gauge,代碼行數:6,代碼來源:Gauge.java


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