android_animation(渐变动画)

在学校刚开始学android控件的时候,没有接触太多复杂的动画,做出来的效果太过生硬。

于是乎:做了个图片渐变的效果。

talk is cheap, show me the code;

private Handler handler = new Handler();
	 ImageView image;
       int alpha=255;
	int b=0;
  public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
         image=(ImageView)findViewById(R.id.curin);
        curin.setAlpha(alpha);
        new Thread( new Runnable() {
			public void run() {
				while(b<2){
					try {
						if(b==0){
							Thread.sleep(2400);
							b=1;
						}
						else{ 
							Thread.sleep(50);
						}
						UpdateApp();
					}catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}).start();
        handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				super.handleMessage(msg);
				image.setAlpha(alpha);
				image.invalidate();

			}
		};
        
    }
    public void UpdateApp(){
    	alpha -= 5;
    	if(alpha<=0){
    		b=2;
    		Intent intent=new Intent(forYo_Activity.this,Start_Activity.class);
    		startActivity(intent);
    		this.finish();
    	}
    	handler.sendMessage(handler.obtainMessage());
    }
    

XML 布局,只需imageview控件;放入所选图片即可;

   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值