4

このアプリでは、ギャラリーを使用してスライドショーで画像を表示しています。うまくいきましたが、アニメーションを追加したいと思います。このコードでは 1 つのアニメーションしか適用できませんが、ギャラリー ビューに 2 つのアニメーション効果を追加したいと考えています。翻訳効果で言うと、右から中央、中央から左です。誰か助けてください。

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);  

    }
}
4

1 に答える 1

2

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);  

それで全部です.....

于 2012-10-12T11:38:53.393 に答える