发布于 2016-12-14 13:58:12
简单的回答:不要在活动之间保持视图的活力。您可以保存和传递状态/变量,但将其保存在内存中并不明智。因此,要么是:
我认为这是唯一合法的方法。我曾经这样做,只是使用Singleton作为表面视图,并在需要时将其从视图中附加/分离,但这并不是最干净的方法。
注释伪代码事务
您应该有以下内容:活动、FragmentA、FragmentB和VideoFragment。活动布局只包含两个视频整体,一个是全屏(用于FragmentA和B),另一个是视频视图。要创建片段,只需右键单击New->Fragment>Blank。首先,您必须在视图中插入片段才能做到这一点,并最终将FragmentA替换为FragmentB,您可以使用以下代码:
Fragment fragmentB = new FragmentB();
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
transaction.replace(R.id.viewHolder, fragmentB);
transaction.commit();您的活动布局应该如下所示:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="nl.coffeeit.clearvoxnexxt.activities.TestActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/viewHolderFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F00"/>
<FrameLayout
android:id="@+id/videoHolder"
android:layout_width="300dp"
android:layout_height="200dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:alpha="0.5"
android:background="#00F"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>https://stackoverflow.com/questions/41062450
复制相似问题