java - Set button size with pixels -


in application control size of button proportionally screen size:

    int screenwidth = displaymetrics.widthpixels;     int screenheight = displaymetrics.heightpixels;     int buttonwidth = (int) (screenwidth * 0.07);     int buttonheight = (int) (buttonwidth * 1.2); 

the button takes same space (for example 5 %) of device's screen size. want button's text takes same space of button area on every device.

i tried this:

   int textsize = (int) (buttonheight * 0.145);    mybutton.settextsize((float) (textsize)); 

i don't know why on bigger screens (such tablets) text uses lot less space of button on smaller screens. ! maybe

try specifying unit of measurement this:

mybutton.settextsize(typedvalue.complex_unit_px, (float) (textsize)); 

settextsize uses sp units default instead of px, might causing issue!


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -