浮动动作按钮扩展 [英] Floating Action Button expansion
本文介绍了浮动动作按钮扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据新的 Android浮动操作按钮的设计准则,.
是否有任何样本/示例可以进行这种转换?
Are there any samples / examples to perform such a transformation?
推荐答案
要使用显示动画,您需要向onCreateView回调中的视图添加一个onLayoutChange侦听器,如下所示:
To use reveal animation you need add a onLayoutChange listener to the view in onCreateView callback like this:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Inflate the layout for this fragment
final View view = inflater.inflate(R.layout.fragment_map_list, container, false);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
v.removeOnLayoutChangeListener(this);
revealView(view);
}
});
}
return view;
}
revealView()方法将在哪里:
where the revealView() method will be:
private void revealView(View view) {
toolbar = view.findViewById(R.id.mytoolbar);
int cx = (view.getLeft() + view.getRight()) / 2;
int cy = (view.getTop() + view.getBottom()) / 2;
float radius = Math.max(infoContainer.getWidth(), infoContainer.getHeight()) * 2.0f;
if (infoContainer.getVisibility() == View.INVISIBLE) {
infoContainer.setVisibility(View.VISIBLE);
ViewAnimationUtils.createCircularReveal(infoContainer, cx, cy, 0, radius).start();
} else {
Animator reveal = ViewAnimationUtils.createCircularReveal(
infoContainer, cx, cy, radius, 0);
reveal.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
toolbar.setVisibility(View.INVISIBLE);
}
});
reveal.start();
}
}
通过这种方式,您应该可以创建动画.这是使用它的方式.只需将其应用于您的fab onClick()方法
In this way you should be able to create your animation. This is the way to use it. Just apply this at your fab onClick() method
这篇关于浮动动作按钮扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文