This project dedicates to help to create layout from code in Android. Because it is better, than axml. This library is just a wrapper around native functionality. A way to mimic all functionality from axml, but without axml.
- Code is clearer.
- Code has type validation.
- Code has IntellySense.
- Code has if/for statements.
- Code has extension methods.
- Code is faster, do not require reflection.
- Code is better for scaling, better for reuse.
- Code layout is simplier to maintain, no need to look into two files at the same time.
- No FindViewById anymore.
- Do not require aapt.exe to run, 5 times faster build time.
Here is a code sample of layout from code using ConstraintLayout.
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = new ConstraintLayout(Context);
var myCaseLog = new AppCompatButton(Context);
myCaseLog.Text = "My Case Log";
myCaseLog.AddInto(view, x => x
.WidthOfParent()
.Height(40.Dp())
.MarginHorizontal(16.Dp())
.BottomToBottomOfParent(8.Dp()));
var postCase = new AppCompatButton(Context);
postCase.Text = "PostCase";
postCase.AddInto(view, x => x
.WidthOfParent()
.Height(41.Dp())
.MarginHorizontal(16.Dp())
.BottomToTopOf(myCaseLog, 8.Dp()));
list = new RecyclerView(Context);
list.SetLayoutManager(new LinearLayoutManager(Context));
list.VerticalScrollBarEnabled = true;
list.AddInto(view, x => x
.WidthOfParent()
.TopToTopOfParent()
.BottomToTopOf(postCase, 8.Dp()));
return view;
}
AndroidLayoutFromCode is a proof of concept. There is no official support. Use at your own risk.