2014-11-27 3 views
5

Angenommen, ich habe mehrere Bilder in einem zeichnungsfähigen Ordner (ex-8 Bilder). Ich möchte alle diese Bilder in einem Bildansicht nacheinander mit links nach rechts Flip-Effekt zeigen (ex-img[0],img[1],……img[8],img[0],img[1],…………). Wie kann ich das machen?Zeige mehrere Bilder in einem BildView nacheinander mit von links nach rechts Flip-Effekt wiederholt

private void AnimateandSlideShow() { 
    image1 = (ImageView)findViewById(R.id.imageView1); 
    image1.setImageResource(img[currentimageindex1%img.length]); 
    currentimageindex1++; 
    Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim); 
    image1.startAnimation(rotateimage);   
} 

Antwort

4

Verwenden Sie benutzerdefinierte Funktion drehen Bild-Handler für das Intervall mit Bild zu ändern, hier i Bild VizeVers Richtung ändern:

private ImageView image1; 
    private int[] imageArray; 
    private int currentIndex; 
    private int startIndex; 
    private int endIndex; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     image1 = (ImageView)findViewById(R.id.imageView1); 
     imageArray = new int[8]; 
     imageArray[0] = R.drawable.one; 
     imageArray[1] = R.drawable.two; 
     imageArray[2] = R.drawable.three; 
     imageArray[3] = R.drawable.four; 
     imageArray[4] = R.drawable.five; 
     imageArray[5] = R.drawable.six; 
     imageArray[6] = R.drawable.seven; 
     imageArray[7] = R.drawable.eight; 

     startIndex = 0; 
     endIndex = 7; 
     nextImage(); 


    } 

    public void nextImage(){ 
     image1.setImageResource(imageArray[currentIndex]); 
     Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim); 
     image1.startAnimation(rotateimage); 
     currentIndex++; 
     new Handler().postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       if(currentIndex>endIndex){ 
        currentIndex--; 
        previousImage(); 
       }else{ 
        nextImage(); 
       } 

      } 
     },1000); // here 1000(1 second) interval to change from current to next image 

    } 
    public void previousImage(){ 
     image1.setImageResource(imageArray[currentIndex]); 
     Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim); 
     image1.startAnimation(rotateimage); 
     currentIndex--; 
     new Handler().postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       if(currentIndex<startIndex){ 
        currentIndex++; 
        nextImage(); 
       }else{ 
        previousImage(); // here 1000(1 second) interval to change from current to previous image 
       } 
      } 
     },1000); 

    } 
+0

danke für deine hilfe bro ... aber ich will flip animation effect beim ändern von bildern ... kannst du mir deine animation xml code ?? bitte –

+0

überprüfen Sie dies: http://androidtutorials60.blogspot.in/2013/09/simple-rotate-animation-in-android.html –

0

Verwenden Sie die Galerieansicht in Ihrer App. Folgen Sie dieser Anleitung

http://www.androidinterview.com/android-gallery-view-example-displaying-a-list-of-images/

hoffe, dies wird Ihnen helfen, Freund :)

+0

Bro, ich bin dynamisch verschiedene Bilder in der Einzelbildansicht .Ich Wechsel angezeigt werden soll Diese Bilder werden nacheinander mit einem Flip-Animationseffekt angezeigt. Nehmen wir an, ein Bild wird jetzt in der Bildansicht angezeigt. Wenn jedoch ein neues Bild erscheint, sollte es mit einem Flip-Effekt angezeigt werden. –

0
<ViewFlipper 
      android:id="@+id/imageCarouselContainer" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@+id/progressSlideshow" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginBottom="0dp" 
      android:animateFirstView="true" 
      android:background="@color/black" 
      android:flipInterval="2000" 
      android:inAnimation="@anim/fade_in" 
      android:orientation="vertical" 
      android:outAnimation="@anim/fade_out" > 

      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_centerVertical="true" 
       android:layout_marginRight="5dp" 
      /> 

      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_centerVertical="true" 
       android:layout_marginRight="5dp" 
      /> 

      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_centerVertical="true" 
       android:layout_marginRight="5dp" 
      /> 
     </ViewFlipper> 

yourViewFlipper.startFlipping();

+0

downvoters interessieren sich zu kommentieren? –

0

verwenden Sie einfach

public class CustomGallery extends Gallery { 

private Handler handler; 

public CustomGallery(Context context) { 
    super(context); 
    handler = new Handler(); 
    postDelayedScrollNext(); 
} 

public CustomGallery(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    handler = new Handler(); 
    postDelayedScrollNext(); 
} 
public CustomGallery(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    handler = new Handler(); 
    postDelayedScrollNext(); 
} 

protected void postDelayedScrollNext() { 
    handler.postDelayed(new Runnable() { 
     public void run() { 
      postDelayedScrollNext(); 
      Log.d("CustomGallery", "dpad RIGHT"); 
      onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null); 
     } 
    }, 1000); 
} 

protected boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) { 
    return e2.getX() > e1.getX(); 
} 

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 
    int kEvent; 
    if (isScrollingLeft(e1, e2)) { 
     Log.d("CustomGallery", "fling LEFT"); 
     kEvent = KeyEvent.KEYCODE_DPAD_LEFT; 
    } else { 
     Log.d("CustomGallery", "fling LEFT"); 
     kEvent = KeyEvent.KEYCODE_DPAD_RIGHT; 
    } 
    onKeyDown(kEvent, null); 
    return true; 
} 
} 
1

Verwenden Sie ViewFlipper und fügen Sie Ihren ImageView innerhalb des ViewFlipper hinzu.

Layout-Datei:

<ViewFlipper 
    android:layout_width="match_parent" 
    android:layout_height="330dp" 
    android:layout_below="@id/textViewid" 
    android:layout_marginTop="20dp" 
    android:id="@+id/flipperid" 
    android:layout_centerInParent="true" 
    android:flipInterval="4000" 
    android:elevation="5dp"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:src="@drawable/pic1" 
     android:scaleType="fitCenter" 
     android:layout_gravity="center_horizontal"/> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:src="@drawable/pic2" 
     android:scaleType="fitCenter" 
     android:layout_gravity="center_horizontal"/> 

</ViewFlipper> 

Dann Code unten in Ihrer Aktivität hinzufügen.

ViewFlipper viewFlipper = (ViewFlipper)findViewById(R.id.flipperid); 

und jetzt automatisch die Bilder spiegeln beginnen von viewFlipper.startFlipping();

Hoffnung ruft dies wird Ihnen helfen ..

+0

Vielen Dank für diese sehr einfache Antwort. Können wir etwas Animation hinzufügen? –

+0

Überprüfen Sie dies https://stackoverflow.com/a/25781173/4608334 Happy Coding !! –

Verwandte Themen