运行时在FloatingActionButton上设置layou

运行时在FloatingActionButton上设置layou

本文介绍了在运行时在FloatingActionButton上设置layout_anchor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试为固定在AppBarLayout上的android.support.design.widget.FloatingActionButton设置动画。我可以在布局xml中将其设置为正确,并且显示良好。但是,我正在向此布局进行共享元素转换,并且在设置视图之前显示了FAB。我试图将可见性设置为GONE和INVISIBLE,但是如果在layout xml中设置了layout_anchor,它们似乎将被忽略。

I am trying to animate a android.support.design.widget.FloatingActionButton that is pinned to my AppBarLayout. I can set it fine within the layout xml and it shows up fine. However i am doing a Shared Element Transition to this layout and the FAB is showing up before the view is set. I tried to set the visibility to GONE and INVISIBLE but they seem to be disregarded if the layout_anchor is set in the layout xml. Is there anyway around this?

我希望该活动加载共享元素过渡,然后在我的FAB中淡出。我只是无法隐藏加载中的FAB。我可以在不使用layout_anchor的情况下做到这一点,但是如果可能的话,最好保留它。

I would like the activity to load with the shared element transition then fade in my FAB. I just can't hide the FAB on load. I could do it without using the layout_anchor but prefer to keep that if possible.

推荐答案

如果您的FAB带有 app:layout_anchor 属性,并且要设置可见性,应使用类似以下内容的东西:

If you have a FAB with the the app:layout_anchor attribute, and you want to set the visibility you should use something like this:

CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
params.setAnchorId(View.NO_ID);
fab.setLayoutParams(params);
fab.setVisibility(View.GONE);

如果要设置 app:layout_anchor 可以使用相同的代码

If you want to set theapp:layout_anchor dinamically you can use the same code:

CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
p.setAnchorId(xxxx);
fab.setLayoutParams(p);

这篇关于在运行时在FloatingActionButton上设置layout_anchor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:23