amulyakhare / TextDrawable

This light-weight library provides images with letter/text like the Gmail app. It extends the Drawable class thus can be used with existing/custom/network ImageView classes. Also included is a fluent interface for creating drawables and a customizable ColorGenerator.
MIT License
3.16k stars 621 forks source link

two lines text with different size is possible? #20

Open LOG-TAG opened 9 years ago

LOG-TAG commented 9 years ago

selection_084

I'm looking for easy solution for the above multi-line requirement !!

caraus commented 9 years ago

Keyboard app. Text app. Cammands and code.:-) Hole lot of hours.

hardikamal commented 9 years ago

Hey @LOG-TAG were u able to achieve that superscript (th) above 15 using this library...Please do let me know if its possible...Thnks

LOG-TAG commented 9 years ago

@hardikamal That is Designed by graphics Designers :) But you can look at this http://stackoverflow.com/questions/3543454/subscript-and-superscript-a-string-in-android http://stackoverflow.com/questions/20597223/android-textview-superscript (look at the ans by @amulyakhare )

hardikamal commented 9 years ago

@LOG-TAG i did this but it not working on textdrawable

sagits commented 9 years ago

Hi guys, i trying to make it:

  @Override
   public void draw(Canvas canvas) {

    // this is already on the lib
    int width = this.width < 0 ? r.width() : this.width;
    int height = this.height < 0 ? r.height() : this.height;
    int fontSize = this.fontSize < 0 ? (Math.min(width, height) / 2) : this.fontSize;
    textPaint.setTextSize(fontSize);

       //this draw one line below another
        int yHeight = 10;
        canvas.drawText(text, width / 2, yHeight, textPaint);
        yHeight += textPaint.descent() - textPaint.ascent();
        canvas.drawText(text2, width / 2, yHeight, textPaint);

}

If you wish to draw with 2 diferents fontsizes, just create another textPaint and set another TextSize.

The problem there is that i dont know how to calculate the text size to draw it on the center of the circle. Can anyone help? Thanks in advance.

SolomonBier commented 9 years ago

Same issue, this ignores \n or line separators

sagits commented 9 years ago

Yes, you have to use split in yours " " and use a for loop to draw each line. I got a new idea, you can create a canvas copy, draw everything and get its size to draw centered on the real one.