How to make the height of a dynamically created TextView exactly 50dp in Android? -


i want make height of dynamically created textview 50dp. tried making dimens.xml file code

<dimen name="imageview_height">50dp</dimen> 

and use

int pixels = getresources().getdimensionpixelsize(r.dimen.imageview_height); 

and on generated textview use.

textview.setheight(pixels); 

however when run it, app crashes , says app name keeps stopping.

you can set this:

textview.setlayoutparams(new layoutparams(width, height)); 

but there different layoutparams depending on layout type. use layout view in. ex: if view in linearlayout, use linearlayout.layoutparams

see post more info: android set height , width of custom view programmatically


Comments