Android--image switch (imageswitcher) instance

Source: Internet
Author: User

The Main.xml code is as follows:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Fill_parent "android:layout_height=" fill_parent "android:orientation=" vertical "&G    T <imageswitcher android:id= "@+id/imageswitcher" android:layout_width= "Wrap_content" Android:layout_        height= "Wrap_content" > </ImageSwitcher> <linearlayout android:layout_width= "Fill_parent" android:layout_height= "fill_parent" android:orientation= "horizontal" > <button android:id= "            @+id/btnprevious "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "            Android:enabled= "false" android:text= "previous picture"/> <button android:id= "@+id/btnnext" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:enabled= "tr UE "Android:text="Next Photo "/> </LinearLayout></LinearLayout> 

. Java code is as follows:

Package Org.lxh.demo;import Android.app.activity;import Android.app.alertdialog;import android.app.Dialog;import Android.app.progressdialog;import Android.content.dialoginterface;import Android.os.bundle;import Android.text.method.scrollingmovementmethod;import Android.view.layoutinflater;import Android.view.View;import Android.view.view.onclicklistener;import Android.view.viewgroup.layoutparams;import Android.view.animation.animationutils;import Android.widget.adapterview;import Android.widget.adapterview.onitemclicklistener;import Android.widget.adapterview.onitemselectedlistener;import Android.widget.button;import Android.widget.imageswitcher;import Android.widget.imageview;import Android.widget.seekbar;import Android.widget.seekbar.onseekbarchangelistener;import Android.widget.Spinner; Import Android.widget.textview;import Android.widget.toast;import Android.widget.viewswitcher.viewfactory;public Class Hello extends Activity {private Imageswitcher imageswitcher = Null;private Button btnprevious = null;private Button btnnext = null;private int[] imgres = new int[] {r.drawable.ispic_a, r.drawable.ispic_ B,r.drawable.ispic_c, R.drawable.ispic_d, R.drawable.ispic_e,};p rivate int foot = 0; @Overridepublic void OnCreate ( Bundle savedinstancestate) {super.oncreate (savedinstancestate);//life cycle Method Super.setcontentview (R.layout.main); Set the layout manager to use This.imageswitcher = (imageswitcher) Super.findviewbyid (r.id.imageswitcher); this.btnprevious = (Button) Super.findviewbyid (r.id.btnprevious); this.btnnext = (Button) Super.findviewbyid (R.id.btnnext);        This.imageSwitcher.setFactory (New Viewfactoryimpl ()); This.imageSwitcher.setInAnimation (Animationutils.loadanimation (this, Android.        r.anim.fade_in)); This.imageSwitcher.setOutAnimation (Animationutils.loadanimation (this, Android. r.anim.fade_out)); This.imageSwitcher.setImageResource (imgres[foot++]); This.btnPrevious.setOnClickListener (new Onclicklistenerprevious ()); This.btnNext.setOnClickListener (new Onclicklistenernext ());} PriVate class Onclicklistenerprevious implements Onclicklistener {public void OnClick (View arg0) { Hello.this.imageSwitcher.setImageResource (imgres[foot--]); Hello.this.checkButtonEnable ();}} Private class Onclicklistenernext implements Onclicklistener {public void OnClick (View arg0) { Hello.this.imageSwitcher.setImageResource (imgres[foot++]); Hello.this.checkButtonEnable ();}} Private class Viewfactoryimpl implements Viewfactory {public View Makeview () {ImageView img = new ImageView (hello.this); IM G.setbackgroundcolor (0xFFFFFFFF); Img.setscaletype (ImageView.ScaleType.CENTER); Img.setlayoutparams (new Imageswitcher.layoutparams (Layoutparams.fill_parent, layoutparams.fill_parent)); return img;}} private void Checkbuttonenable () {if (This.foot < this.imgres.length-1) {this.btnNext.setEnabled (true);} else{ This.btnNext.setEnabled (false);} if (This.foot = = 0) {this.btnPrevious.setEnabled (false);} else{this.btnprevious.setenabled (True);}}

The effect is as follows:


Source code Download: http://download.csdn.net/detail/yayun0516/8380329


Android--image switch (imageswitcher) instance

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.