ObjectAnimatorでTextViewの内容を書き換える

ObjectAnimatorおもろいなー setNumber(int)を持つNumberTextViewというクラスを作り

public class NumberTextView extends AppCompatTextView {

    public NumberTextView(Context context) {
        super(context);
    }

    public NumberTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NumberTextView(Context context, AttributeSet attrs,
            int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setNumber(int number) {
        setText(String.valueOf(number));
    }
}

ObjectAnimatorでエイッとすると

ObjectAnimator objectAnimator = ObjectAnimator.ofInt(binding.numberTextView, "number", 0, 10000);
objectAnimator.setDuration(10 * 1000);
objectAnimator.setInterpolator(new LinearInterpolator());
objectAnimator.start();

数値がテキストとして表示される

f:id:tomorrowkey:20160301093402g:plain

単にリフレクション使って値を設定しているだけなのかなー。