TextView improperly displaying in Layout in Android 6 and below -


i dynamically creating views in oncreate() , use setmargins() , setlayoutparams() position them on layout.

this works expected in android 7 parameters ignored in android 6 , below.

i assume has views not being created in oncreate() or dont know why work in android 7, or how around it.

below example code of problem , screenshots visualization.

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      viewgroup viewgroup = (viewgroup) findviewbyid(android.r.id.content);      relativelayout.layoutparams viewparam = new relativelayout.layoutparams(             relativelayout.layoutparams.wrap_content,             relativelayout.layoutparams.wrap_content);      viewparam.setmargins(200, 400, 0, 0);      textview mytextview = new textview(this);      mytextview.settext("hello text");      mytextview.settextsize(             typedvalue.complex_unit_px, 50);      mytextview.setgravity(gravity.center);      mytextview.setlayoutparams(viewparam);     viewgroup.addview(mytextview);  } 

view on android 6 view on android 7


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -