如何动画新设计支持图书馆FloatingActionButton [英] How to animate FloatingActionButton of new Design Support Library
本文介绍了如何动画新设计支持图书馆FloatingActionButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的5个不同的片段一TabLayout。在3这些片段的 android.support.design.widget.FloatingActionButton
应该出现。现在,我只需设定FAB的标签发生变化时的可见度,但我想有一个动画,其中FAB进来和出去。
我怎样才能在Android中实现这一目标?
I am using a TabLayout with 5 different fragments. On 3 of these fragments a android.support.design.widget.FloatingActionButton
should appear. Right now I simply set the visibility of the FAB when the tab changes, but I would like to have an animation, where the FAB comes in and out.
How can I achieve this in Android?
推荐答案
由于我不想延长 FloatingActionButton
,我做了这种方式:
Because I did not want to extend the FloatingActionButton
, I made it this way:
FloatingActionButton createButton;
// ...
Animation makeInAnimation = AnimationUtils.makeInAnimation(getBaseContext(), false);
makeInAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) { }
@Override
public void onAnimationRepeat(Animation animation) { }
@Override
public void onAnimationStart(Animation animation) {
createButton.setVisibility(View.VISIBLE);
}
});
Animation makeOutAnimation = AnimationUtils.makeOutAnimation(getBaseContext(), true);
makeOutAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
createButton.setVisibility(View.INVISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) { }
@Override
public void onAnimationStart(Animation animation) { }
});
// ...
if (createButton.isShown()) {
createButton.startAnimation(makeOutAnimation);
}
// ...
if (!createButton.isShown()) {
createButton.startAnimation(makeInAnimation);
}
这篇关于如何动画新设计支持图书馆FloatingActionButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文