我尝试使用以下代码为 ImageView 启动 AlphaAnimation:
ImageView view;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.prueba);
view=(ImageView)findViewById(R.id.icon);
view.setAlpha(0x00);
view.setVisibility(View.VISIBLE);
view.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent e) {
switch (e.getAction()) {
case MotionEvent.ACTION_DOWN:
Log.i("Down v", "x:" + e.getX() + " y:" + e.getY());
view.startAnimation(new AlphaAnimation(0x22, 0xFF));
// break;
case MotionEvent.ACTION_MOVE:
Log.i("Move", "x:" + e.getX() + " y:" + e.getY());
break;
case MotionEvent.ACTION_UP:
Log.i("Up", "x:" + e.getX() + " y:" + e.getY());
view.setAlpha(0x00);
break;
case MotionEvent.ACTION_OUTSIDE:
Log.i("Out", "x:" + e.getX() + " y:" + e.getY());
break;
default:
Log.i("None", "nada");
}
return false;
}
});
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.i("Click", "es un click");
}
});
}
这段代码应该是让 ImageView 在被触摸时出现,但什么也没发生。有什么解决办法吗?