Java Day 3: Labeling Buttons with Strings


Pixels – corresponds to actual pixels on the screen.

Inches – based on the physical size of the screen.

Millimeters – based on the physical size of the screen.

Points – 1/72 of an inch based on the physical size of the screen.

Density-independent Pixels – an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both “dip” and “dp”, though “dp” is more consistent with “sp”.

Scale-independent Pixels – this is like the dp unit, but it is also scaled by the user’s font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user’s preference.

NOTE: comments can’t be insterted between tags


Every text displayed should be wrapped into a string for packaging sake. The program gets a little piffy (note the caution icon–yellow triangle– on “large text”) when you try to “hardcode” text. So, day one of coding my new app, Calcu, is making strings so the buttons have something legit to display. A big learning moment was installing the Obelus (the division symbol– yeah I didn’t know the name of it either!). Using a character map to find the unicode, I was able to reference this particular character with “&#247.” Very exciting.

xml code
View using Eclipse’ WYSIWYG
I made this using RelativeLayout

Text Alignment

I aligned the zero in the text box with gravity. Android:gravity=”top|right” different from html. I like it. I imagine a magic gravity wand drawing all text into that part of the box. It’s not a matter of alignment. It’s forces of nature at work!

Links for symbols:
Unicode and HTML – Wikipedia, the free encyclopedia

List of XML and HTML character entity references – Wikipedia, the free encyclopedia.


One comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s