Android,改变触摸的alpha



我设置图像视图的alpha值如下:

myImageView.setAlpha(0);

Then on touch:

myImageView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
v.setAlpha(100);

但是当我触摸图像时alpha值不会改变,我知道触摸被拾取了,因为我可以记录一个字符串来检查。


编辑

如果我把原来的alpha值设为0然后添加渐变动画,渐变动画不起作用,下面是动画:

fadeInAnimation = new AlphaAnimation(0.00f, 1.00f);
fadeInAnimation.setDuration(1000);

如果我将原始视图的alpha值设置为0.10那么它会从0逐渐淡出到0.10而不是一直到1.00f

setAlpha取从01的浮点数,其中0表示完全透明,1表示完全不透明。尝试输入0.5f,看看会发生什么。

编辑:

实现动画监听器的一种方法:
public class myActivity extends Activity{
   @Override
   public void onCreate(Bundle noNeed){
      **** setup ****
      fadeInAnimation = new AlphaAnimation(0.00f, 1.00f);
      fadeInAnimation.setDuration(1000);
      fadeInAnimation.setAnimationListener(new myAnimationListener());
   }

   private class myAnimationListener implement Animation.AnimationListener{
      public void onAnimationStart(Animation animation){
         ** Do stuff you want to do just before the animation **
      }
      public void onAnimationRepeat(Animation animation){
         ** Do stuff you want to do as an animation repeats itself
            (i.e. it has started and finish at least once and will go again) **
      }
      public void onAnimationEnd(Animation animation){
         ** Do stuff you want to do once an animation finishes **
      }
   }
}

最新更新