神刀安全网

Xamarin Android: Create Android AnimationDrawble App

Let’s start

Step 1:Open Visual Studio->New Project->Templates->Visual C#->Android->Blank App

Select Blank App. Then give Project Name and Project Location.

Xamarin Android: Create Android AnimationDrawble App

Step 2:

Next go to Solution Explorer-> Project Name->Resources->drawable then Right Click to Add->New Item then open new Dialog box.

Xamarin Android: Create Android AnimationDrawble App

Step 3:That Dialog box to Select XML File and give Name for Animation.xml.

Xamarin Android: Create Android AnimationDrawble App

Step 4:

Next open Solution Explorer-> Project Name->Resources->drawable->Animation.xml click to open Design View. Then give following code.

Xamarin Android: Create Android AnimationDrawble App

XML Code:

<?xml version="1.0" encoding="UTF-8" ?>   <animation-list xmlns:android="http://schemas.android.com/apk/res/android" >   <item android:drawable="@drawable/img1" android:duration="100" />   <item android:drawable="@drawable/img2" android:duration="100" />   <item android:drawable="@drawable/img3" android:duration="100" />   </animation-list>  

Step 5: Next open Solution Explorer-> Project Name->Resources->layout->Main.axml click to open Design View

Xamarin Android: Create Android AnimationDrawble App

Step 6:Select Toolbar Drag and Drop ImageView Design.

Xamarin Android: Create Android AnimationDrawble App

Xamarin Android: Create Android AnimationDrawble App

AXML Code:

<?xml version="1.0" encoding="utf-8"?>   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   android:orientation="vertical"   android:layout_width="fill_parent"   android:layout_height="fill_parent"   android:minWidth="25px"   android:minHeight="25px">   <ImageView   android:src="@android:drawable/ic_menu_gallery"   android:layout_width="match_parent"   android:layout_height="wrap_content"   android:id="@+id/imageView1" />   </LinearLayout>  

Step 7: Next open MainActivity.cs page, then Add Namespace and following code.

Xamarin Android: Create Android AnimationDrawble App

Namespace: using Android.Graphics.Drawables;

C# Code:

using System;   using Android.App;   using Android.Content;   using Android.Runtime;   using Android.Views;   using Android.Widget;   using Android.OS;   using Android.Graphics.Drawables;   namespace Animation   {       [Activity(Label = "Animation", MainLauncher = true, Icon = "@drawable/icon")]       public class MainActivity : Activity       {           private AnimationDrawable Animation;           protected override void OnCreate(Bundle bundle)           {               base.OnCreate(bundle);               // Set our view from the "main" layout resource               SetContentView(Resource.Layout.Main);               // Load the animation from resources               Animation = (AnimationDrawable)Resources.GetDrawable(Resource.Drawable.animation);               ImageView imageView = FindViewById<ImageView>(Resource.Id.imageView1);               imageView.SetImageDrawable(Animation);           }       }   }   

Step 8:

Then Debug and run the app Working Animation Rotate in Image.

Xamarin Android: Create Android AnimationDrawble App

Finally, we have successfully created Xamarin Android AnimationDrawble Application.

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Xamarin Android: Create Android AnimationDrawble App

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址