Android TextView Set Line spacing issues (setlinespacing, Linespacingextra, Linespacingmultiplier)

Source: Internet
Author: User

In recent projects, you need to use a custom control. There is a component to get the height of the drawing text, open the TextView source, there is a method Getlineheight ()

     Public int getlineheight () {        return fastmath.round (mtextpaint.getfontmetricsint (null) * Mspacingmult + Mspacingadd);    }
Getlineheight's comments are as follows:

/**
@return the height of one standard line in pixels. Note that markup* within the text can cause individual lines to being taller or shorter* than this height, and the layout may Contain additional first-* or last-line padding. */ returns the height of a row. Note the text inside the tag may be above or below this height, and the layout may contain additional first or last line filled portions.
We just get the height of a line of text and don't calculate the spacing.
so  You can use Fastmath.round (Mtextpaint.getfontmetricsint (null)). 

On the internet also found some ways to get text height by other means. After testing, it was found that the above method was used to get the most accurate height. The code for the test is not posted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.