Android element layout: with XML or in code? -
how can layout elements in android programmatically, , practical alternative using xml / code split typically used in android?
coming ios background, can connect ui elements in storyboard code in body files, i've found creating elements in code offers greater overview , reduces coding time. there's lot less toggling between 2 files.
android seems place greater importance on use of xml layout apple storyboards, , i'm wondering if it's bridge far force element creation activities themselves.
i limited extent question refers coding style (thereby inviting off-topic discussion), not exclusively , insofar influences ux (and maybe performance), it's relevant.
using xml
easier using java , more flexible control : example of button
inside linearlayout
button button = new button(this); button.settext("my button"); button.setwidth(100);// in pixel not recommended button.setheight(100); button.setbackgroundcolor(color.red); button.setx(100); button.sety(100); button.settextsize(typedvalue.complex_unit_px, 20);// convert sp linearlayout container = new linearlayout(this); linearlayout.layoutparams layoutparams = new linearlayout.layoutparams(linearlayout.layoutparams.match_parent, linearlayout.layoutparams.match_parent); container.setlayoutparams(layoutparams); container.addview(button);
it may take 15min of coding using xml drag , drop , using xml editor
Comments
Post a Comment