First contact with Xamarin.android.
Because the domestic xamarin data is rare, I mostly refer to Java native code, slowly groping over.
I have found out the results of the advertised, I hope Yimeimei can take a little detour, but also hope you can make a contribution.
If you learn relativelayout, that LinearLayout natural extremely easy.
Dynamic add learned, static add still far?
1. Create Relativelayout
New Relativelayout (this. Context);
2. Adding controls
2.1 Base Additions
New TextView (this. Context); Test.addview (testtext);
2.2 Top Add (same as bottom add, etc.)
New Relativelayout (Thisnew TextView. Context);
New Relativelayout.layoutparams (RelativeLayout.LayoutParams.WrapContent, RelativeLayout.LayoutParams.WrapContent); Testtextrp.addrule (Layoutrules.alignparenttop); Test.addview (TESTTEXT,TESTTEXTRP);
Android uses Layoutparams to control the spatial layout of controls.
The common layout of C # is modified by the spatial properties of the control, which is not suitable for Android.
I have to tell you that if you need to make changes to the control layout parameters, be sure to use Layoutparams. Romans do
2.3 Adding after another control
Relativelayout Test =NewRelativelayout ( This. Context); TextView Testtext=NewTextView ( This. Context); Testtext.text="I'm number 1th ."; Relativelayout.layoutparams TESTTEXTRP=NewRelativelayout.layoutparams (RelativeLayout.LayoutParams.WrapContent, RelativeLayout.LayoutParams.WrapContent); Testtextrp.addrule (Layoutrules.alignparenttop); Test.addview (TESTTEXT,TESTTEXTRP); TextView Nexttext=NewTextView ( This. Context); Nexttext.text="I'm number 2nd ."; Relativelayout.layoutparams NEXTTEXTRP=NewRelativelayout.layoutparams (RelativeLayout.LayoutParams.WrapContent, RelativeLayout.LayoutParams.WrapContent);//Watch this .Testtext.id =View.generateviewid (); Nexttextrp.addrule (layoutrules.below,testtext.id); Test.addview (Nexttext, NEXTTEXTRP);
Test Picture:
The key point here is to assign a value to the ID of the previous control. (I'm using a system-generated value.) You can try other values, such as: Wait a minute. )
If you do not assign a value, then the actual effect is two textview will overlap.
After testing, the default ID for each control is-1.
2.4 To Be continued
Originating From: https://www.cnblogs.com/nanyunan/p/9189057.html
Xamarin.android Relativelayout