Xamarin.android Relativelayout

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.