Android Imageswitcher and Textswitcher

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-size:20px;color:rgb(247,150,70);">Imageswitcher:</span></p></p><p><p><span style="font-size:20px;color:rgb(247,150,70);"><span style="color:rgb(0,0,0);font-size:16px;">Activity_main.xml</span><br></span></p></p><pre class="brush:java;toolbar:false"><relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"      xmlns:tools= "http://schemas.android.com/tools"     android:layout_width= "match_parent"     android:layout_height= "match_parent"     android:paddingbottom= "@ Dimen/activity_vertical_margin "    android:paddingleft=" @dimen/activity_horizontal_margin "     android:paddingright= "@dimen/activity_horizontal_margin"      android:paddingtop= "@dimen/activity_vertical_margin"     tools:context= " Com.example.imageswitch.MainActivity " >    <ImageSwitcher         android:id= "@+id/imageswitcher1_1"          android:layout_width= "match_parent"         android:layout_height = "match_parent" &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBsp; android:layout_alignparenttop= "true"        >     </ImageSwitcher></RelativeLayout><!--    android:inanimation= "@ Android:anim/slide_in_left "        android:outanimation=" @android: Anim /slide_out_right "         --></pre><p><p> <span style="font-size:20px;color:rgb (247,150,70); ><span style=" color:rgb (0,0,0); font-size:16px; "> </span> MianA Ctivity <br> </p></p><pre class="brush:java;toolbar:false">Package com.example.imageswitch;import android.app.activity;import android.os.bundle;import  android.view.Menu;import android.view.MenuItem;import android.view.MotionEvent;import  android.view.view;import android.view.view.ontouchlistener;import android.widget.imageswitcher; Import android.widget.imageview;import android.widget.viewswitcher.viewfactory;public class  mainactivity extends activity implements viewfactory ,ontouchlistener{private  imageswitcher imageswitch;private int [] images={r.drawable.kobe0,r.drawable.kobe1, R.drawable.kobe3,r.drawable.kobe4,r.drawable.kobe6,};p rivate int index; // The subscript for the picture to be displayed @overrideprotected void oncreate (bundle savedinstancestate)  {super.oncreate ( savedinstancestate); setcontentview (r.layout.activity_main); imageswitch= (imageswitcher)  findViewById ( R.id.imageswitcher1_1);//set up a factory to create ImageView Imageswitch.setfactOry (this);//set Touch-screen Event Imageswitch.setontouchlistener (this);} Viewfactory Factory interface method, through this method, to the Imageswitch component to provide two @overridepublic view makeview ()  {// todo  auto-generated method stubimageview imageview=new imageview (this); Imageview.setimageresource (images[0]); return imageview;} Define two X coordinate points  float startx=0.0f;      //start position  float endx=0.0F;         //end Position//touch Screen Event monitoring method @overridepublic boolean ontouch (View  v, motionevent event)  {if (event.getaction () ==motionevent.action_down) {startx=event.getX () ; return true;} Else if (event.getaction () ==motionevent.action_up) {endx=event.getx ();//judge left swipe if (startx-endx>20) {index= ( Index+1) < (images.length-1) ++index:0;imageswitch.setimageresource (images[index]);// Set the animation effect Imageswitch.setinanimation (this, android) in your Code. r.anim.fade_in); imageswitch.setoutanimation (this, android. r.anim.fade_out);} Judging right SlideIf (endx-startx>20) {index= (index-1) >0?--index:images.length-1;imageswitch.setimageresource (images[index] ); imageswitch.setinanimation (this, android. r.anim.slide_in_left); imageswitch.setoutanimation (this, android. r.anim.slide_out_right);}} return true;}}</pre><p><p>Textswitcher is similar to imageswitcher, just change Imageswitcher to Textswitcher</p></p><p><p>Set picture resource to set text</p></p><p><p>This article is from the "matengbing" blog, make sure to keep this source http://matengbing.blog.51cto.com/11395502/1882816</p></p><p><p>Android Imageswitcher and Textswitcher</p></p></span>

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.