我试图通过在屏幕上移动手指来更改ImageView
的alpha。我有一个OnTouchListener
,在MotionEvent.ACTION_MOVE
我已经输入了以下代码。 Log
显示移动手指时alpha值正常变化,但setAlpha
方法不会更改视图的alpha值。图像只出现一次,具有随机的alpha透明度并保持不变。我做错了什么?
public boolean onLongClick(View v) {
if(v.getId() == R.id.button2){
longClicked = true;
}
}
private OnTouchListener dialpadTouchListener = new OnTouchListener() {
public boolean onTouch(View view, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE){
if (longClicked) {
mainView.addView(msg, msgParams);
mainView.addView(remove, removeParams);
longClicked = false;
}
int alpha = (int)(viewY - event.getRawY());
msg.setAlpha(alpha);
Log.i(TAG,"Alpha set to " + alpha);
return true;
}
}
}