Android: ImageSwitcher

后端 未结 1 1097
时光取名叫无心
时光取名叫无心 2020-12-29 16:28

I have a ImageSwitcher and 2 buttons...\"Next\" and \"Previous\" to slide images...But its animate my sliding only in one side from left to the right...How to fix that ? tha

1条回答
  •  孤城傲影
    2020-12-29 17:23

    change the in/out animation in the onClickListeners. try this: (not checked for syntax etc...)

    @Override public void onCreate(Bundle savedInstanceState) {    
     super.onCreate(savedInstanceState);    
     setContentView(R.layout.main);    
    
    
    
     imageSwitcher.setImageResource(imageIDs[0]);     
     nextButton = (Button) findViewById(R.id.next);    
     nextButton.setOnClickListener(new OnClickListener() {       
       public void onClick(View v) {  
     Animation out= AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right);     
     Animation in= AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);   
     imageSwitcher = (ImageSwitcher) findViewById(R.id.switcher1);    
     imageSwitcher.setFactory(this); 
     imageSwitcher.setInAnimation(in);    
     imageSwitcher.setOutAnimation(out);        
        imageSwitcher.setImageResource(imageIDs[1]);     
         }    
     });    
      previousButton = (Button) findViewById(R.id.previous);     previousButton.setOnClickListener(new OnClickListener() { 
             public void onClick(View v) {  
     Animation out= AnimationUtils.loadAnimation(this, android.R.anim.slide_out_left);     
     Animation in= AnimationUtils.loadAnimation(this, android.R.anim.slide_in_right);   
     imageSwitcher.setFactory(this); 
     imageSwitcher.setInAnimation(in);    
     imageSwitcher.setOutAnimation(out);  
               imageSwitcher.setImageResource(imageIDs[0]);     
        }   
      }); 
     } 
    
     public View makeView() {   
      ImageView imageView = new ImageView(this);   
      imageView.setBackgroundColor(0xFF000000);   
      imageView.setScaleType(ImageView.ScaleType.CENTER);  
       imageView.setLayoutParams(new ImageSwitcher.LayoutParams(             LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
        return imageView; } 
    

    0 讨论(0)
提交回复
热议问题