質問

私は、リソースのイメージを示すImageViewのに連続したアニメーションを(ScaleAnimationを言う)を適用したいと思います。アニメーションは、ボタンによってトリガーされます。例えば、私は漸進各ボタンをクリックすると画像を拡大したいと思います。

は、私はアニメーションにfillAfter = "true" を設定しました。しかし、すべてのアニメーションは、ImageViewのが元の状態からスタート。 ImageViewのは、その状態をリセットし、アニメーションではなく、前のアニメーションの最終的な状態から始めるので、常に同じであるかのように思える。

私は間違って何をしているのですか?

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button button = (Button)findViewById(R.id.Button01);
    button.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            animate();

        }});
}

private void animate() {
    ImageView imageView = (ImageView) findViewById(R.id.ImageView01);

    ScaleAnimation scale = new ScaleAnimation((float)1.0, (float)1.5, (float)1.0, (float)1.5);
    scale.setFillAfter(true);
    scale.setDuration(500);
    imageView.startAnimation(scale); 
}
役に立ちましたか?

解決

  

これは、ImageViewのがリセットかのように思えます   その状態とアニメーションが常にあります   同じ、代わりのから始まります   前のアニメーションの最終状態。

正確に!私は確かfillAfter="true"のための使用がありますが、私はまだそれのためのポイントを考え出したていないんです。

あなたがする必要がどのような

は関連性の各AnimationListenerAnimationを設定し、実際にあなたのアニメーションの終了状態を永続化するために、リスナーのonAnimationEnd()に何かをしています。私はかなり確実何だろう「終了状態を永続化」への道じゃないので、私はScaleAnimationでプレイしていません。これはAlphaAnimationから1.0に行く0.0あった場合は、例えば、INVISIBLEでウィジェットGONEまたはonAnimationEnd()になるだろう。

他のヒント

私は同じ問題を抱えていたし、簡単に別のアニメーションを使用するには、次のコードを作成しました。それが唯一の翻訳と、今私は、スケーリングを使用していないとしてのアルファレベルをサポートしていますが、簡単に、より多くの機能をサポートするように拡張することができます。

私はアニメーションを開始する前に、スクロールと可視性をリセットし、それは私がアニメーションオン/オフに必要なだけのためです。

そして「DOEND」ブールが再帰のスタックオーバーフローを避けるためにそこにある(scrollToは、いくつかのあいまいな理由でonAnimationEnd呼び出す...)

private void setViewPos(View view, Animation anim, long time){
    // Get the transformation
    Transformation trans = new Transformation();
    anim.getTransformation(time, trans);

    // Get the matrix values
    float[] values = new float[9];
    Matrix m = trans.getMatrix();
    m.getValues(values);

    // Get the position and apply the scroll
    final float x = values[Matrix.MTRANS_X];
    final float y = values[Matrix.MTRANS_Y];
    view.scrollTo(-(int)x, -(int)y);

    // Show/hide depending on final alpha level
    if (trans.getAlpha() > 0.5){
        view.setVisibility(VISIBLE);
    } else {
        view.setVisibility(INVISIBLE);       
    }
}

private void applyAnimation(final View view, final Animation anim){
    view.scrollTo(0, 0);
    view.setVisibility(VISIBLE);

    anim.setAnimationListener(new AnimationListener(){
        private boolean doEnd = true;

        @Override
        public void onAnimationEnd(Animation animation) {
            if (doEnd){
                doEnd = false;
                setViewPos(view, animation, anim.getStartTime() + anim.getDuration());
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationStart(Animation animation) {
        }

    });

    view.startAnimation(anim);
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top