欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

怎么在Android中使用FontMetrics對象計(jì)算坐標(biāo)

這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)怎么在Android中使用FontMetrics對象計(jì)算坐標(biāo),文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

讓胡路網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)建站,讓胡路網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為讓胡路超過千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請找那個售后服務(wù)好的讓胡路做網(wǎng)站的公司定做!

Canvas繪制文本時,使用FontMetrics對象,計(jì)算位置的坐標(biāo)。

public static class FontMetrics {
  /**
   * The maximum distance above the baseline for the tallest glyph in 
   * the font at a given text size.
   */
  public float  top;
  /**
   * The recommended distance above the baseline for singled spaced text.
   */
  public float  ascent;
  /**
   * The recommended distance below the baseline for singled spaced text.
   */
  public float  descent;
  /**
   * The maximum distance below the baseline for the lowest glyph in 
   * the font at a given text size.
   */
  public float  bottom;
  /**
   * The recommended additional space to add between lines of text.
   */
  public float  leading;
}

它的各基準(zhǔn)線可以參考下圖:

怎么在Android中使用FontMetrics對象計(jì)算坐標(biāo)

上圖其實(shí)是通過代碼畫出來的,具體代碼如下:

/** 繪制FontMetrics對象的各種線 */
mPaint.reset();
mPaint.setColor(Color.WHITE);
mPaint.setTextSize(80);
// FontMetrics對象
FontMetrics fontMetrics = mPaint.getFontMetrics();
String text = "abcdefg";
// 計(jì)算每一個坐標(biāo)
float textWidth = mPaint.measureText(text);
float baseX = 30;
float baseY = 700;
float topY = baseY + fontMetrics.top;
float ascentY = baseY + fontMetrics.ascent;
float descentY = baseY + fontMetrics.descent;
float bottomY = baseY + fontMetrics.bottom;
// 繪制文本
canvas.drawText(text, baseX, baseY, mPaint);
// BaseLine描畫
mPaint.setColor(Color.RED);
canvas.drawLine(baseX, baseY, baseX + textWidth, baseY, mPaint);
mPaint.setTextSize(20);
canvas.drawText("base", baseX + textWidth, baseY, mPaint);
// Base描畫
canvas.drawCircle(baseX, baseY, 5, mPaint);
// TopLine描畫
mPaint.setColor(Color.LTGRAY);
canvas.drawLine(baseX, topY, baseX + textWidth, topY, mPaint);
canvas.drawText("top", baseX + textWidth, topY, mPaint);
// AscentLine描畫
mPaint.setColor(Color.GREEN);
canvas.drawLine(baseX, ascentY, baseX + textWidth, ascentY, mPaint);
canvas.drawText("ascent", baseX + textWidth, ascentY + 10, mPaint);
// DescentLine描畫
mPaint.setColor(Color.YELLOW);
canvas.drawLine(baseX, descentY, baseX + textWidth, descentY, mPaint);
canvas.drawText("descent", baseX + textWidth, descentY, mPaint);
// ButtomLine描畫
mPaint.setColor(Color.MAGENTA);
canvas.drawLine(baseX, bottomY, baseX + textWidth, bottomY, mPaint);
canvas.drawText("buttom", baseX + textWidth, bottomY + 10, mPaint);

相信通過以上程序,能夠很好的理解topLine,buttomLine,baseLine,ascentLine,descentLine。
另外:Paint類有兩個方法

/**
 * Return the distance above (negative) the baseline (ascent) based on the
 * current typeface and text size.
 *
 * @return the distance above (negative) the baseline (ascent) based on the
 *     current typeface and text size.
 */
public native float ascent();
 
/**
 * Return the distance below (positive) the baseline (descent) based on the
 * current typeface and text size.
 *
 * @return the distance below (positive) the baseline (descent) based on
 *     the current typeface and text size.
 */
public native float descent();

ascent():the distance above the baseline(baseline以上的height)
descent():the distance below the baseline(baseline以下的height)

所以ascent() + descent() 可以看成文字的height。

到此為止,怎么獲取文字的height和width都已經(jīng)揭曉了:

獲取height : mPaint.ascent() + mPaint.descent()

獲取width : mPaint.measureText(text)

上述就是小編為大家分享的怎么在Android中使用FontMetrics對象計(jì)算坐標(biāo)了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

標(biāo)題名稱:怎么在Android中使用FontMetrics對象計(jì)算坐標(biāo)
文章分享:http://aaarwkj.com/article18/iippgp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、域名注冊、App開發(fā)、關(guān)鍵詞優(yōu)化建站公司、外貿(mào)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站
国产精品久久久久大屁股精品性色| 国产精品五月婷婷六月丁香| 亚洲av最近在线观看| 成人性生交大片免费男同| 日韩精品视频播放一区| 在线成人免费日韩视频| 亚洲黄色录像一区二区人妻黑人| 国产爆操美女在线观看| 国产成人av三级在线观看| 国产亚洲精品视频在线| 亚洲精品熟女国产国产老熟女| 九色视频在线观看91| 偷拍丝袜美腿亚洲超碰| 黄片超刺激在线看在线| 国产精品福利手机在线观看| 亚洲家庭伦理在线观看| 亚洲国产精品福利在线| 中日韩一二三四区在线看| 在线青青草视频免费观看| 日本一区二区三区免费黄视频| 亚洲国产欧美日韩在线一区| 亚洲一区精品二人人爽久久| 久久精品亚洲欧美麻豆| 日韩欧美在线观看一区二区| 亚洲国产天堂久久综合| 国产高清亚洲一区亚洲二区| 国产精品久久久久精品日日三级 | 日韩精品欧美精品一区二区| 中文字幕日韩欧美第一页| 蜜桃臀视频一区二区三区| 国产一区二区三区性色| 国产精品国产三级国产专播精品| 亚洲精品一区久久狠狠欧美| 免费久久人人爽人人爽| 亚洲成人日韩国产欧美| 熟女少妇a一区二区三区| 日本福利一区二区三区| 欧美日韩精品国产精品| 美女视频一区二区三区在线观看| 青青草原在线观看网站| 亚洲女同另类在线播放视频|