Search code examples
androidstring-formattingdashclock

Dashclock extension: Aligning expanded body text to form a table


I am unable to align text in a table format in my dashclock extension's body. Following is the format I want (first column left aligned, rest columns right aligned):

   A               2               3
   BC              5              10
   DEF            22               3

In the code I try aligning the following way

String.format("%-10s %10s %10s\n", val1, val2, val3);

When I log the result of the above formatting it prints in the correct and intended way in logcat. But when I deploy the app and run it as part of the dashclock application, the alignment is completely off. The alignment when displayed in dashclock extension looks like:

   A           2               3
   BC            5              10
   DEF            22               3

I tried searching and looking into the DashClockExtension class to see if something is possible but couldn't. Also the expandedBody method in ExtensionData does not take SpannedString as argument, only String.

Any ideas as how to get the alignment right in the device?


Solution

  • There isn't currently a way to do this because the font used for displaying expanded body content isn't a monospace font, meaning each character has a different width. Feel free to file a feature request for representing tabular data though! http://dashclock.com/issues