【问题标题】:Android gallery slideshow animationAndroid画廊幻灯片动画
【发布时间】:2011-08-17 09:58:39
【问题描述】:

我正在开发一个画廊应用程序,在这个应用程序中,我使用画廊在幻灯片中显示图像。它工作正常,但我想添加一些动画。我只能使用此代码应用一个动画,但我想在图库视图中添加两个动画效果。 在翻译效果中说,从右到中心和从中心到左。请任何人帮助我。

public void slidShow(){

     Runnable runnable = new Runnable() {

        @Override
        public void run() {
            myslideshow();
            handler.postDelayed(this, 3000);                
        }
    };
    new Thread(runnable).start();
}

private void myslideshow(){
    PicPosition = gallery.getSelectedItemPosition() +1;             
    if (PicPosition >=  bitmaps.size()){
        PicPosition =  gallery.getSelectedItemPosition(); //stop    
    } 
    else{
        Animation inFromRight = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, +1.0f,
                Animation.RELATIVE_TO_PARENT,  0.0f,
                Animation.RELATIVE_TO_PARENT,  0.0f,
                Animation.RELATIVE_TO_PARENT,  0.0f);
        inFromRight.setDuration(500);
        inFromRight.setInterpolator(new AccelerateInterpolator()); 
        gallery.startAnimation(inFromRight);
        gallery.setSelection(PicPosition);  

    }
}

【问题讨论】:

    标签: android android-gallery


    【解决方案1】:

    使用基于 Xml 的动画 在文件夹 res/anim/animate.xml 中创建一个 Xml 文件

    放代码

      <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="true">
        <translate 
            android:fromXDelta="0%p" android:toXDelta="50%p" // change this to decide the range
            android:duration="500" android:startOffset="0"/>
        <translate 
            android:fromXDelta="0%p" android:toXDelta="100%p" 
            android:duration="500" android:startOffset="500"/>// change this to increase the 
    time for image to stay 
    
    </set>
    

    现在在你的函数 myslideshow() 中改变

    Animation inFromRight =  AnimationUtils.loadAnimation(this, R.anim.animate);
    gallery.startAnimation(inFromRight);
            gallery.setSelection(PicPosition);  
    

    仅此而已.....

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-12
      • 2011-12-06
      • 2013-12-28
      • 2018-07-10
      相关资源
      最近更新 更多