如果可能的话,我在UI中有一个视图,从技术上讲,它是RelativeLayout中的扩展ImageView。我想在用户点击屏幕时(甚至有onShowPress回调),在特定坐标显示一个Drawable from resources(一个带渐变或框架的小PNG)作为视觉反馈。最简单的方法是什么?我不想修改从中膨胀UI的layout.xml,我也不太热衷于重写onDraw来在那里做额外的工作。
这是使用视图动画类实现这一点的一种简单方法:
final ImageView aboutButton = (ImageView) findViewById(R.id.AboutButton);
aboutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Animation myAnim2 = AnimationUtils.loadAnimation(LaunchActivity.this, R.anim.buttons);
aboutButton.startAnimation(myAnim2);
myAnim2.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation animation) {
//do on click after animation ends
Intent intent = new Intent(LaunchActivity.this, MyDialog.class);
startActivity(intent);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
//change the backround of the button etc on click etc...
}
});
}});