Centering text in a button?

by CyberQat » Wed, 11 Nov 2009 03:42:30 GMT


Sponsored Links
 Hi Guys,

Ive just started fooling around with programming my Motorola Droid.
I'm programmatic ally laying out an interface such that the text
contained in my Button is sized at layout time to fit the button.  My
questions are:

(1) I know the pixel size of the button, what is the best way to set
the text size to fit the button size?
(2) I can't seem to get it to center.  I've tried a Gravity of 11 and
that helps, but ist still not right.  How do I get my text to center
itself properly horizontally and vertically in the button?

Thanks

--



Centering text in a button?

by CyberQat » Thu, 12 Nov 2009 14:19:22 GMT


 Some more info

The text is perfectly centered (but tiny) if I lave it at the default
setting.  If I try to scale it
up to match the button size however I lose vertical centering :(

Ive tried looking at the drawing code but it is massively complex.

Anyone know a soln?




--


Sponsored Links


Other Threads

1. Dialog (built using AlertDialog.Builder) not complete when showing dialog in runOnUiThread

I have a game activity in which i have a dialog which is created in
the onCreateDialog method of the activity:

        case VICTORY_DIALOG:

                                String[] items={"Next Level", "Play Again", 
"Exit"};

                                AlertDialog.Builder builder = new 
AlertDialog.Builder(this);
                                builder.setMessage("You won!")
                                .setCancelable(false)
                                .setItems(items, new 
DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface 
dialog, int id) {
                                                if(id==0) {
                                                        
SpaceWarsActivity.this.nextLevel();
                                                } else if(id==1) {
                                                        
SpaceWarsActivity.this.loadGame();
                                                } else if(id==2) {
                                                        
SpaceWarsActivity.this.onFinishGame();
                                                }
                                        }
                                });
                                dialog=builder.create();
                                break;


When the game ends i open this dialog from the game thread (not the ui
thread) with the following code:

                                                activity.runOnUiThread(new 
Runnable() {
                                                        public void run() {
                                                                
activity.showDialog(VICTORY_DIALOG);
                                                        }
                                                });

However... the dialog is just a small empty rectangle. No title, no
items, nothing!
The buttons (setPositiveButton,setNegativeButton,setNeutralButton) are
working though.

Wat am i doing wrong?

Thanks in advance
--~--~---------~--~----~------------~-------~--~----~

2. Accelerometer is cukoo???

I see an acceleration of -9 in the y-direction ( due to gravity, of
course). Now, keeping the phone fixed, not rotating the screen or
anything, I interrupt the app my pressing the call button and then
coming back, I see an acceleration of +9 in the x-direction. This
switching of the coordinates happens without onAccuracyChanged being
called, so how on Earth can we consistently use the accelerometer's
output?

Please shed some light on this. Is this fixed in SDK 1.5?
--~--~---------~--~----~------------~-------~--~----~

3. ToggleButton - how to implement iPhone-style ToggleButton?

4. Google Talk Shared Status Messages

5. How to find out screen status: active/dark?

6. How to change a Uri to a file?

7. Using Prebuilt Toolchain with configure and make