2016-11-29 6 views
3

したがって、私はこの1つのように、配列変数を持って、3つのプログレスバーが含まれていますObjetctAnimatorは、私は、カスタムビューを構築しています

float[] progress = new float[3]; 

そして私は「ObjectAnimator」を使用して、特定の進捗エントリを更新します。

public void setProgress(int index, float progress) { 
    this.progress[index] = (progress<=100) ? progress : 100; 
    invalidate(); 
} 

public void setProgressWithAnimation(int index, float progress, int duration) { 
    PropertyValuesHolder indexValue = PropertyValuesHolder.ofInt("progress", index); 
    PropertyValuesHolder progressValue = PropertyValuesHolder.ofFloat("progress", progress); 

    ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(this, indexValue, progressValue); 
    objectAnimator.setDuration(duration); 
    objectAnimator.setInterpolator(new DecelerateInterpolator()); 
    objectAnimator.start(); 
} 

が、私はこの警告を取得しています:

私もセッターで試してみましたが、アレイ(setProgress (float[] progress))が含まれているが、それでもエラーました:Method setProgress() with type float not found on target class

をだから私ここに関連するメソッドです「、LO後

おかげ

+0

単に 'ObjectAnimator#ofInt(オブジェクトのターゲット、文字列propertyNameの、int型を使用します。.. 。値) ' – pskink

+0

@pskink。ありがとうございますが、私はすでにそれを試してみました: 'メソッドsetProgress()は、対象のクラスにfloat型が見つかりませんでした '、申し訳ありません。 – AsfK

答えて

0

をObjectAnimatorで配列変数を使用する方法を知って喜んでいるでしょう試してみると、それはObjectAnimatorを使ってこれを行うことができるようです。私もdocでこれを見つけた:

The object property that you are animating must have a setter function (in camel case) in the form of set(). Because the ObjectAnimator automatically updates the property during animation, it must be able to access the property with this setter method. For example, if the property name is foo, you need to have a setFoo() method. If this setter method does not exist, you have three options:

  • Add the setter method to the class if you have the rights to do so.

  • Use a wrapper class that you have rights to change and have that wrapper receive the value with a valid setter method and forward it to the original object.

  • Use ValueAnimator instead.

、Googleのアドバイスとして、私はValueAnimatorにしようと、それが正常に動作しています:

public void setProgressWithAnimation(float progress, int duration, final int index) { 
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(progress); 
    valueAnimator.setDuration(duration); 
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 
     @Override 
     public void onAnimationUpdate(ValueAnimator valueAnimator) { 
      setProgress((Float) valueAnimator.getAnimatedValue(), index); 
     } 
    }); 
    valueAnimator.start(); 
} 
関連する問題