安卓开发笔记,一些有用的方法记录(随时记录)

1、淡入淡出动画的实现

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_crossfade);

		mContentView = findViewById(R.id.content);//要出现的view
		mLoadingView = findViewById(R.id.loading_spinner);//要消失的view

		// Initially hide the content view.
		mContentView.setVisibility(View.GONE);//先把要出现的view设置为gone,节约内存。

		// Retrieve and cache the system's default "short" animation time.
		mShortAnimationDuration = getResources().getInteger(
				android.R.integer.config_shortAnimTime);//这个变量是系统提供的一种动画时间,他会确保动画执行的更一致和更精致
	}
private void crossfade() {

	// Set the content view to 0% opacity but visible, so that it is visible
	// (but fully transparent) during the animation.
	mContentView.setAlpha(0f);
	mContentView.setVisibility(View.VISIBLE);

	// Animate the content view to 100% opacity, and clear any animation
	// listener set on the view.
	mContentView.animate()
			.alpha(1f)//从0到1
			.setDuration(mShortAnimationDuration)
			.setListener(null);

	// Animate the loading view to 0% opacity. After the animation ends,
	// set its visibility to GONE as an optimization step (it won't
	// participate in layout passes, etc.)
	mLoadingView.animate()
			.alpha(0f)
			.setDuration(mShortAnimationDuration)
			.setListener(new AnimatorListenerAdapter() {
				@Override
				public void onAnimationEnd(Animator animation) {
					mLoadingView.setVisibility(View.GONE);//在动画的最后要把它设置为gone
				}
			});

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值