i love writing code. but if you'reanything like me, then creating even the mostsophisticated logic for your apps seems easierthan crafting a great user interface.
Android relativelayout, designs evolve overtime, and testing every single change inyour layouts on devices can be tedious. enter the layout editor, atool built into android studio
that lets you edit and previewyour layouts in real time, without the need torecompile and deploy the apk on to an actualdevice or emulator. the layout editorautomatically kicks in whenever you open an xml layout file. the design view lets you easilyadd and manipulate components by dragging them from thepalette onto the stage. visual cues help you positionviews relative to each other, taking into accountthe parent node's class
and required layout parameters. you can edit other viewproperties in the inspector or change the views place in thehierarchy in the component tree pane. there's a handy trick you canuse when you've set up a view but then decide that youwant to change its class. just right-click a view andselect the desired component from the morphing menu. be aware that there are certainrestrictions in place to only
allow changes that make sense. so you won't be able to morph alinear layout into a text view, for example. whenever you see that partsof your view hierarchy can be reused inother layouts, there's also a refactoringcalled extract layout. when you enable it, thesubtree you selected will be moved intoa separate resource and included inyour current layout.
when you open thenew file for editing, you can see it'sstill shown embedded in the originalhierarchy for previewing. that's because androidstudio added a special hint to your xml when itperformed the refactoring. to see it, let's switchto editing raw xml by pressing on the text tab. notice how insteadof the visual editor, there is now alive preview window
that updates in real timeas you work on the code. if you always prefer to see codeinstead of the default design view, just enable the preferxml editor option here. the hint for the rendererthat i mentioned before actually consists of two parts. first, we have the new toolsnamespace on the root xml node. the other is a set ofspecial annotations that don't affectthe runtime but are processed by android studio.
here, you can seethe show in property that renders thefile you're working on in a context of anotherlayout in place of the include tag. it's certainly useful, butthere's another type of hint that really boostedmy productivity that i wish someone hadpointed out to me sooner. you can actually overridemost of the view properties just by prefixing themwith the tools namespace.
seems simple, but look athow it could work for you. ever had a layout with blanktext views because it needs an adapter to supply data, likein a list view, for example? add dummy text usingthe tools namespace, and make your layoutimmediately readable. what if parts of your layoutare set to gone or invisible and only shown dependingon runtime conditions? just override it with toolsvisibility for design time. as you can see, the layouteditor is a fantastic tool,
and it's availablein android studio. if you want to learn more orif you have any other layout
editing tips, share them ongoogle+ in the android studio community. be sure to check out the othervideos in the android studio devbytes series.