在我的应用程序中,我正在尝试实现一个MiniControlFragment,它会在用户决定关闭时显示ExpandedControlsActivity(Mini控制器的全屏版本).我没有以声明方式将其添加到xml布局中,而是需要以编程方式执行此操作.
所以我创建了自己的类,扩展了MiniControllerFragment:
public class CastControllingFragment extends MiniControllerFragment
{
@Override
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle)
{
View view = super.onCreateView(layoutInflater, viewGroup, bundle);
if (view != null) {
FrameLayout.LayoutParams frameLayoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
view.setLayoutParams(frameLayoutParams);
}
return view;
}
public static void show(FragmentActivity activity) {
FragmentManager fragmentManager = activity.getSupportFragmentManager();
if (fragmentManager.findFragmentById(R.id.castMiniController) == null)
{
View rootView = activity.findViewById(R.id.fragment_container);
if (rootView instanceof ViewGroup)
{
fragmentManager.beginTransaction().add(R.id.fragment_container, new CastControllingFragment()).commit();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我实例并把它添加到片段中的交易Activity的 …