本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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];
}
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}