android - Smoother ImageSwitcher - How to? -


i'm trying out simple project scroll between images it's animation bad now.

when slide switch between images doesnt "attach" finger while swipe, instead fades out awkwardly , next image comes in sliding. think has animation parameters used don't know else use.

what want achieve scrolling horizontally between tabs in app, while 1 image sliding out, other 1 sliding in next it, attached each other sideways.

here code:

xml:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical" >      <imageswitcher         android:id="@+id/splashscreenimages"         android:layout_width="fill_parent"         android:layout_height="fill_parent" > </imageswitcher>  </relativelayout> 

java:

package com.test.imageswitchertest02;  import android.os.bundle; import android.app.activity; import android.util.log; import android.view.menu; import android.view.motionevent; import android.view.view; import android.view.view.ontouchlistener; import android.view.animation.animationutils; import android.widget.imageswitcher; import android.widget.imageview; import android.widget.viewswitcher.viewfactory;  public class mainactivity extends activity implements viewfactory {      imageswitcher splashswitcher;     integer[] screenslist = { r.drawable.splash_screen1, r.drawable.splash_screen2, r.drawable.splash_screen3 };     int curindex = 0;     int downx, upx;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          splashswitcher = (imageswitcher) findviewbyid(r.id.splashscreenimages);         splashswitcher.setfactory(this);         splashswitcher.setinanimation(animationutils.loadanimation(this,android.r.anim.fade_in));         splashswitcher.setinanimation(animationutils.loadanimation(this,android.r.anim.fade_out));          splashswitcher.setimageresource(screenslist[curindex]);         splashswitcher.setontouchlistener(new ontouchlistener() {              @override             public boolean ontouch(view v, motionevent event) {                 if (event.getaction() == motionevent.action_down) {                     downx = (int) event.getx();                     log.i("event.getx()", " downx " + downx);                     return true;                 } else if (event.getaction() == motionevent.action_up) {                     upx = (int) event.getx();                     log.i("event.getx()", "upx" + downx);                      if (upx - downx > 100) {                         // curindex current image index being viewed                         curindex--;                         if (curindex < 0) {                             curindex = screenslist.length - 1;                         }                          splashswitcher.setinanimation(animationutils.loadanimation(mainactivity.this,android.r.anim.slide_in_left));                         splashswitcher.setinanimation(animationutils.loadanimation(mainactivity.this,android.r.anim.slide_out_right));                          splashswitcher.setimageresource(screenslist[curindex]);                     } else if (downx - upx > -100) {                         curindex++;                         if (curindex > 2) {                             curindex = 0;                         }                         splashswitcher.setinanimation(animationutils.loadanimation(mainactivity.this,r.anim.slide_in_right));                         splashswitcher.setinanimation(animationutils.loadanimation(mainactivity.this,r.anim.slide_out_left));                          splashswitcher.setimageresource(screenslist[curindex]);                      }                      return true;                 }                 return false;             }         });      }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.main, menu);         return true;     }      @override     public view makeview() {         imageview = new imageview(this);         i.setscaletype(imageview.scaletype.fit_center);         return i;     }  } 


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -