- Hands-On Mobile Development with .NET Core
- Can Bilgin
- 279字
- 2021-06-24 13:55:31
Xamarin on Android – Mono Droid
Following the same methodology, we can recreate the Xamarin.Forms view we created using Xamarin.Android using a native project template. In order to do this, we can reuse the existing Xamarin classic project that we used for iOS and add an Android application project instead:
This will create a standard boilerplate application project for Xamarin.Android with a single view and associated layout file. If you open the created Main.axml file, the designer view will be loaded, which can be used to create our welcome view:
When handling the Android XML layout files, developers are given the option to either use the designer or the source view. By using the designer view to create the welcome view, you would have to drag and drop the text view control and adjust the alignment, layout, and gravity properties for the label.
Using the source view, you can also paste the following layout declaration to see what the application looks like when run on the Android platform:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/textView1"
android:text="Welcome to Xamarin!"
android:gravity="center_vertical"
android:textAlignment="center" />
</LinearLayout>
When we finally compile and run our first Xamarin.Android application, you will see the welcome view that was created on Xamarin.Forms and Xamarin.iOS.
The Xamarin.Android platform functions a little more like .NET Core. Unlike Xamarin.iOS, there are no restrictions on code generation, so the Mono Droid runtime execution is done using the JIT compiler, which is responsible for providing the IL packages that are part of the application package. The Mono Droid runtime exists in the application package in the form of native code that replaces the .NET Core runtime:
For Xamarin.Forms applications, the same compilation and runtime procedures, such as AOT and JIT, apply, depending on the targeted platform.