开发者

Android, change alpha on touch

开发者 https://www.devze.com 2023-04-10 02:29 出处:网络
I set the alpha of my image view like so: myImageView.setAlpha(0); Then on touch: myImageView.setOnTouchListener(new View.OnTouchListener() {

I set the alpha of my image view like so:

myImageView.setAlpha(0);

Then on touch:

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

But the alpha doesn't change when I touch the image, I know the touch is picked up as I can log a string to check.


EDIT

If I set my original alpha to 0 a开发者_开发百科nd then add a fade in animation, the fade in animation doesnt work, here's the animation:

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

If I set the alpha of the original view to something like 0.10 then it fades from 0 to 0.10 not all the way to 1.00f


setAlpha takes a float from 0 to 1 where 0 means completely transparent and 1 means fully opaque. Try an input of 0.5f and see what happens.

EDIT:

One way to implement an Animation Listener:

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 **
      }

   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消