view - Android: getting width available within layout -


i'm wondering whether there way find out space available views within layout.

to little more precise: in activity 2 textviews displayed side side. second 1 contains pretty text, i'd check, whether text can displayed on screen or whether it's large. if that's case i'll display smaller version of text instead (as android doesn't display text on multiple lines default). i'm using code this:

windowmanager windowmanager = (windowmanager) getsystemservice(window_service); display display = windowmanager.getdefaultdisplay(); point screensize = new point(); display.getsize(screensize); int screenwidth = screensize.x;  if (tvtitle.getwidth() + tvdescription.getwidth() > screenwidth) {     tvdescrition.settext(getstring(r.string.descritption_short)); } 

but doesn't work: widths smaller screen, long version used. but: text isn't displayed completely, last words missing.

i guess problem is, layout using padding , therefore reducing space available.

so how fix this? ideas extremely welcome :-)

you can measure width of text(string) in pixels. using method:

paint.measuretext(titlestring + descriptionstring);

if exceeds total screen width - horizontal margin - horizontal padding can go short description.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -