Skip to content Skip to sidebar Skip to footer

Vertically Aligning Suffix With Tab Space In Android Textview

I have rows (of horizontal LinearLayout) with a TextView at the end that displays time. An this is how it looks: Now I need the suffix (am/pm) in all rows to be aligned vertically

Solution 1:

Maybe using tabs is the most efficient, but the gap is pretty big and not configurable. If you need all those rows in a single view group, you may try to check out RelativeLayout: align am/pm vertically on common left, and put hours to the left and on the baseline. This is the most flexible way, since you can control relative positions and margins, but computation-wise it's less efficient because it requires extra calculation upon laying out elements.

As per aligning colons — in most fonts (not just monospace) digits are designed to take equal space, so just align the numbers on the right (e.g. in relative layout) and it should do.

Solution 2:

Solution 3:

You can use a 2-column TableLayout. The first column is the time without AM/PM and the second column is just the AM/PM. Set the gravity of the first column to "end" or "right" and the times will be lined up at the colons if you are using a fixed width font.

Post a Comment for "Vertically Aligning Suffix With Tab Space In Android Textview"