布局之间的淡入效果 [英] Fade effect between layouts

查看:79
本文介绍了布局之间的淡入效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为对象,我将在两个布局之间重现淡入淡出的效果. 现在我有这种情况:

As by object, I would reproduce fade effect between two layout. Now I've this situation:

LinearLayout l;
LinearLayout l2;

我已经使用

l.setVisibility(View.GONE);
l2.setVisibility(View.VISIBLE);

我想在这种转换之间添加淡入淡出效果,该怎么办?

I want add fade effect between this transiction, how I can do it?

推荐答案

使用R.anim.fade_out& .R.anim.fade_in您可以创建执行此操作的动画.我本人对此并不了解,但是这里有一个关于android动画的教程:动画教程

Using R.anim.fade_out & .R.anim.fade_in you can create an animation which does this. I don't know much about this myself but heres a tutorial regarding animations in android: Animation Tutorial

P.S.本教程不是我的教程,因此信誉不属于我.

P.S. This tutorial is not mine thus credit does not go out to me.

AnimationSet set = new AnimationSet(true);

Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(50);
set.addAnimation(animation);

animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f
);
animation.setDuration(100);
set.addAnimation(animation);

LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
l.setLayoutAnimation(controller);

淡出动画

public static Animation runFadeOutAnimationOn(Activity ctx, View target) {
  Animation animation = AnimationUtils.loadAnimation(ctx,android.R.anim.fade_out);
  target.startAnimation(animation);
  return animation;
}

我猜你可以尝试这样的事情,我从教程中复制粘贴了动画,但由于我没有Android开发经验,所以我不知道动画的确切功能.另一个示例可以是示例2

I'm guessing you can try something like this, I copy pasted the animation from the tutorial I don't know what it does exactly as I have no experience with Android development. Another example could be Example 2

这篇关于布局之间的淡入效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆