It's a nice boot interface effect. Android Control Imageswitcher Implementation _android

Source: Internet
Author: User

This example for you to share the Android control Imageswitcher implementation of the Guide interface code, for your reference, the specific content as follows

Effect Chart:

Layout code:

<?xml version= "1.0" encoding= "UTF-8"?> <framelayout xmlns:android=
"http://schemas.android.com/apk/" Res/android "
       android:layout_width=" fill_parent "
       android:layout_height=" fill_parent ">

  < Imageswitcher
    android:id= "@+id/imageswitcher"
    android:layout_width= "fill_parent"
    android:layout_ height= "Fill_parent" >
  </ImageSwitcher>

  <relativelayout
    android:layout_width= "Fill_ Parent "
    android:layout_height=" wrap_content "
    android:orientation=" vertical ">

    < LinearLayout
      android:id= "@+id/ll_view"
      android:layout_width= "fill_parent"
      android:layout_height = "Wrap_content"
      android:layout_alignparentbottom= "true"
      android:layout_marginbottom= "30DP"
      Android:gravity= "Center_horizontal"
      android:orientation= "Horizontal" >
    </LinearLayout>
  </RelativeLayout>
</FrameLayout>

Page code:

public class Imageswitcheractivity extends activity implements Viewswitcher.viewfactory, View.ontouchlistener {private Int[] imgids;//picture ID array private int currentposition;//currently selected picture ID serial number private imageswitcher Mimageswitcher;//imagaswitcher Reference private float downx;//Press the x coordinate of the dot private imageview[] tips;//point points Group private linearlayout linearlayout;//mount point container @O
    Verride protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);

    Setcontentview (R.layout.activity_switcher); Imgids = new int[]{r.drawable.bg, R.DRAWABLE.C2, r.drawable.c3, r.drawable.c4, R.drawable.c5, R.DRAWABLE.C6,

    R.drawable.c7, R.drawable.c8, r.drawable.c9}; Mimageswitcher = (imageswitcher) Findviewbyid (r.id.imageswitcher);//instantiated Imageswitcher mimageswitcher.setfactory ( this); Set Factory Mimageswitcher.setontouchlistener (this);//Set Ontouchlistener, we switch the picture linearlayout by Touch event (Linearla yout) Findviewbyid (r.id.ll_view)//Indicator Layout tips = new IMAGEVIEW[IMGIDS.LEngth];
      for (int i = 0; i < imgids.length i++) {ImageView Mimageview = new ImageView (this);
      Tips[i] = Mimageview; Linearlayout.layoutparams layoutparams = new Linearlayout.layoutparams (New Viewgroup.layoutparams (LayoutParams.WRAP
      _content, layoutparams.wrap_content));
      Layoutparams.rightmargin = 3;

      Layoutparams.leftmargin = 3;
      Mimageview.setbackgroundresource (r.drawable.page_indicator_unfocused);
    Linearlayout.addview (Mimageview, layoutparams);
    The position of the previous interface currentposition = Getintent (). Getintextra ("position", 0);

    Mimageswitcher.setimageresource (Imgids[currentposition]);

  Setimagebackground (currentposition);
      //Set the background of the selected tip private void setimagebackground (int selectitems) {for (int i = 0; i < tips.length; i++) {
      if (i = = Selectitems) {tips[i].setbackgroundresource (r.drawable.page_indicator_focused); else {Tips[i].setbackgroundresource (r.drawable.page_indicator_unfocuSED);
    @Override public View Makeview () {final ImageView i = new ImageView (this);
    I.setbackgroundcolor (0xff000000);
    I.setscaletype (ImageView.ScaleType.CENTER_CROP);
    I.setlayoutparams (New Imageswitcher.layoutparams (Layoutparams.match_parent, layoutparams.match_parent));
  return i; @Override public boolean Ontouch (View v., motionevent event) {switch (event.getaction ()) {case Motioneve Nt.
      Action_down: {downx = Event.getx ();//finger press X coordinate break;
        Case MOTIONEVENT.ACTION_UP: {Float lastx = Event.getx ();
            When lifting the X coordinate is greater than the time to display the previous picture if (Lastx > Downx) {if (currentposition > 0) {//Set animation
            Mimageswitcher.setinanimation (Animationutils.loadanimation (Getapplication (), r.anim.left_in));
            Mimageswitcher.setoutanimation (Animationutils.loadanimation (Getapplication (), r.anim.right_out));
            currentposition--; Mimageswitcher. Setimageresource (imgids[currentposition% imgids.length]);
          Setimagebackground (currentposition);
          else {Toast.maketext (getapplication (), "Already the first", Toast.length_short). Show (); } if (Lastx < Downx) {if (CurrentPosition < imgids.length-1) {MIMAGESWI
            Tcher.setinanimation (Animationutils.loadanimation (Getapplication (), r.anim.right_in));
            Mimageswitcher.setoutanimation (Animationutils.loadanimation (Getapplication (), r.anim.lift_out));
            currentposition++;
            Mimageswitcher.setimageresource (Imgids[currentposition]);
          Setimagebackground (currentposition);
          else {Toast.maketext (getapplication (), "to the Last", Toast.length_short). Show ();
    }} break;
  return true;
 }

}

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.