【发布时间】:2015-07-20 21:39:23
【问题描述】:
我当前的问题是我正在尝试触发 Animator 在两个活动之间进行转换。我的目标是创建从一个 Activity 到另一个 Activity 的循环显示过渡。
我开始收到此错误:“无法在分离视图上启动此动画师!”
我环顾 Stack Overflow,发现:Cannot start this animator on a detached view! reveal effect
一种解释似乎是第二个 Activity 的视图尚未膨胀,这就是 Animator 无法启动的原因。
线程中的人使用此作为解决方案:
@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);
toggleInformationView(view);
}
});
}
return view;
}
但是,我对这里发生的事情有点困惑。看来他也在夸大 Activity 的布局。如果是这样,我应该不打电话:
setContentView(R.layout.activity_bnew_account);
在Activity的onCreate方法中?我应该在覆盖的 onCreateView 中使用布局充气器来充气活动布局吗?感谢您提供有关如何解决此问题的任何建议。
【问题讨论】:
标签: android animation transition