android - slide views which are within view animator from right to left for previous views -


i want slide views within viewanimator right left previous views.

this layout

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical">      <linearlayout         android:id="@+id/btn_layout"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_alignparentbottom="true"         android:orientation="horizontal">          <button             android:id="@+id/btn_previous"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="previous" />          <button             android:id="@+id/btn_next"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="next" />     </linearlayout>      <viewanimator         android:id="@+id/view_animator"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_above="@id/btn_layout">      </viewanimator>   </relativelayout> 

this activity

package com.example.ronem.testing;  import android.os.bundle; import android.support.v7.app.appcompatactivity; import android.view.view; import android.view.viewgroup; import android.view.animation.animation; import android.view.animation.animationutils; import android.widget.button; import android.widget.imageview; import android.widget.viewanimator;  /**  * created ronem on 3/17/16.  */ public class viewanimatoractivity extends appcompatactivity {     button btnprev, btnnext;     viewanimator viewanimator;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.view_animator_layout);          btnprev = (button) findviewbyid(r.id.btn_previous);         btnnext = (button) findviewbyid(r.id.btn_next);         viewanimator = (viewanimator) findviewbyid(r.id.view_animator);          addimageview();          animation inanimation = animationutils.loadanimation(this, android.r.anim.slide_in_left);         animation outanimation = animationutils.loadanimation(this, android.r.anim.slide_out_right);          viewanimator.setinanimation(inanimation);         viewanimator.setoutanimation(outanimation);           btnprev.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 viewanimator.showprevious();             }         });          btnnext.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 viewanimator.shownext();             }         });     }      private void addimageview() {         int[] drawable = new int[]{r.drawable.a, r.drawable.b, r.drawable.c, r.drawable.d, r.drawable.e, r.drawable.images};          (int = 0; < drawable.length; i++) {             imageview imageview = new imageview(this);             imageview.setimageresource(drawable[i]);             imageview.setlayoutparams(new viewgroup.layoutparams(viewgroup.layoutparams.wrap_content,viewgroup.layoutparams.wrap_content));             viewanimator.addview(imageview);         }     } } 

whenever click on next button imageview slides left right works fine, when click on previous button shows previous imageview seems fine problem image view sliding left right again want slide image right left when click on previous button. attribute should add viewanimator ? suggestions helpful.

in next button click listener, set in/out animations way did originally. in previous button click listener, set in/out animations opposite way. way go desired direction based on button click.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -