Xamarin.android: Bind java jar file +android display gif pictures

Source: Internet
Author: User

First, Introduction

In Xamarin development, sometimes we want to do a function, but this feature has already been written in Java, and packaged into a jar file. Then we can just take each other's jar file instead of re-writing the code in C #.

More detailed information about the bind jar can be seen in https://developer.xamarin.com/guides/android/advanced_topics/binding-a-java-library/ , this is just the simplest binding.

Two, Bind JAR

Now I want to do a function to make the GIF picture in the phone, normal Android control is no way to display, so I went to Baidu search, finally found, find someone else good code and compiled into a jar file, so I need to bind his jar file to my vs project.

1. Create a new project and place a GIF file into the drawable subfolder of the Resource folder

2. Create a new project in the current solution, but select "Binding Library" in the project options

The following items are created.

3. Locate the Jars folder, put the jar file in, and set its properties "Build Action" to "Embeddedjar". Then rebuild the project, if not an error indicates that bind succeeded.

4. Referencing the project used for bind in our first created project

After the reference, double-click the reference name to see the namespace and the class and method names inside.

Third, complete the demo

1. Add the following code to the Main.axml file, Com.ant.liao.GifView represents the Gifview control that references Com.ant.liao

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "vertical"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent">    <Com.ant.liao.GifViewAndroid:id= "@+id/gif1"Android:layout_height= "Wrap_content"Android:layout_width= "Wrap_content"Android:paddingright= "14px"android:enabled= "false"android:visibility= "visible" />    <TextViewAndroid:id= "@+id/tsxt"Android:layout_height= "Wrap_content"Android:layout_width= "Wrap_content"Android:paddingright= "4px"android:enabled= "false"Android:text= "Click the Angel" /></LinearLayout>

2. Add the following code to the MainActivity.cs file

usingSystem;usingAndroid.app;usingandroid.content;usingAndroid.runtime;usingandroid.views;usingAndroid.widget;usingAndroid.os;usingCom.Ant.Liao;namespacegifdemo{[Activity (Label="Gifdemo", Mainlauncher =true, Icon ="@drawable/icon")]     Public classmainactivity:activity, Imageview.ionclicklistener {PrivateCom.Ant.Liao.GifView gif;//Defining GIF Controls        PrivateBoolean f =true; protected Override voidOnCreate (Bundle bundle) {Base.            OnCreate (bundle);            Setcontentview (Resource.Layout.Main); GIF= findviewbyid<com.ant.liao.gifview>(RESOURCE.ID.GIF1); //gif. Setshowdimension (a);gif.            Setgifimagetype (Com.Ant.Liao.GifView.GifImageType.Cover); Gif.            Setgifimage (Resource.Drawable.demo); Gif. Setonclicklistener ( This);//Set Click Pause        }         Public voidOnClick (View v) {if(f) {gif.                Showcover (); F=false; }            Else{gif.                ShowAnimation (); F=true; }        }    }}

3.

Xamarin.android: Bind java jar file +android display gif pictures

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.