使用计时器使ImageView可见

时间:2014-02-25 15:25:11

标签: android imageview

我知道这个问题已经得到解答,但CountdownTimer不适用于我的方法。

所以基本上我点击一个按钮后会有按钮和textview的动画。但是我想要一个带有计时器的imageview。因为imageview是textview的一部分,我想向用户展示它。 有什么帮助吗?

这是我的代码:

onCreate方法:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imageView2 = (ImageView)findViewById(R.id.imageView2);
        edittext = (EditText)findViewById(R.id.edittext);  
        leatseatbutton = (Button)findViewById(R.id.letseatbutton);  

        register=(Button)findViewById(R.id.register);
        signin1button=(Button)findViewById(R.id.signin1button);
        signinbutton_fb=(Button)findViewById(R.id.signinbutton_fb);
        cancel=(Button)findViewById(R.id.cancel);
        imageView1 = (ImageView)findViewById(R.id.imageView1);

首先是onClickListener

        leatseatbutton.setOnClickListener(new View.OnClickListener() {  

   @Override  
   public void onClick(View v) {    
       RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
               LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
       params.width = 175;
       params.height = 40;
       params.setMargins(75, 240, 0, 0);
       leatseatbutton.setLayoutParams(params);
    edittext.setVisibility(View.VISIBLE); 
    TranslateAnimation slide = new TranslateAnimation(0, 0, 100,0 );   
    slide.setDuration(1000);   
    slide.setFillAfter(true);   
    slide.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            imageView2.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });
    edittext.startAnimation(slide); 
   }  
  }); 

第二个onClickListener

    signinbutton.setOnClickListener(new View.OnClickListener() {  

   @Override  
   public void onClick(View v) { 
       RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
               LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
       params.width = 175;
       params.height = 40;
       params.setMargins(75, 240, 0, 0);
       signinbutton.setLayoutParams(params);
    edittext.setVisibility(View.VISIBLE); 
    TranslateAnimation slide = new TranslateAnimation(0, 0, 100,0 );   
    slide.setDuration(1000);   
    slide.setFillAfter(true);   
    edittext.startAnimation(slide); 
   }  
  });
    }

1 个答案:

答案 0 :(得分:1)

也许您需要使用AnimationListener

    ....
    TranslateAnimation slide = new TranslateAnimation(0, 0, 100,0 );

    slide.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            imageview.setVisible(View.VISIBLE);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    slide.setDuration(1000);   
    slide.setFillAfter(true);   
    edittext.startAnimation(slide); 
    ....