When I'd ran this code, it did nothing, I'm sure that this event is called when I touch the button. but It doesn't change the opacity of imageView.
View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
ObjectAnimator fadeAltAnim = ObjectAnimator.ofFloat(R.id.imgTest, "alpha", 0.2f);
fadeAltAnim.start();
}
};
findViewById(R.id.dummy_button).setOnTouchListener(mDelayHideTouchListener);
Is there anything wrong with my code?
Try this code, its using ViewPropertyAnimator :
Its always good to set a duration, so the Animation knows how long its supposed to run.
EDIT : You might want to attach it to a MotionEvent if you are using onTouchListener , something like :
EDIT 2 :
If you want to use a Button its best to use an OnClickListener instead of onTouchListener, if you want to attach an Image you have to initiate it(for example in an ImageView) :