Android - How to add a View progamatically to an Activity's Absolute Layoute setting it's possition? -
i have form several views on it, last 1 spinner bound adapter it's data web server via post request, @ end append additional entry "other...". if option selected on spinner, new edittext view @ bottom user enters custom value, i've managed edittext view show on screen, it's positioned @ top, on other views , can't seem find way make appear @ bottom, below spinner want to, here code have far:
edittext suggestcarrierfield = new edittext(getbasecontext()); suggestcarrierfield.setlayoutparams(new viewgroup.layoutparams( viewgroup.layoutparams.fill_parent, viewgroup.layoutparams.wrap_content)); suggestcarrierfield.sethint("suggest carrier"); ((absolutelayout) findviewbyid(r.id.createaccountview)).addview(suggestcarrierfield); ((absolutelayout) findviewbyid(r.id.createaccountview)).invalidate();
using absolutelayout, need use absolutelayout.layoutparams, rather viewgroup.layoutparams.
int width = 100, height = 25, x = 0, y = 200; absolutelayout.layoutparams lp = new absolutelayout.layoutparams(width, height, x, y); suggestcarrierfield.setlayoutparams(lp);
having said that, urge consider implementing relativelayout (or linearlayout) instead... absolutelayout deprecated, , reason. there many different android devices different sized screens now, absolutelayout won't work across them all.
Comments
Post a Comment