android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“Activity原生页面”
android:textSize=“20dp”
app:layout_constraintLeft_toLeftOf=“parent”
app:layout_constraintRight_toRightOf=“parent”
app:layout_constraintTop_toTopOf=“parent” />
<RelativeLayout
android:id=“@+id/fragment_container”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
app:layout_constraintTop_toBottomOf=“@+id/textView”
app:layout_constraintLeft_toLeftOf=“parent”
app:layout_constraintRight_toRightOf=“parent” />
</androidx.constraintlayout.widget.ConstraintLayout>
3.2 将activity中的一部分替换为Fragment
fragmentManager
.beginTransaction()
.add(
R.id.fragment_container,
flutterFragment,
TAG_FLUTTER_FRAGMENT
)
.commit();
说明:将相对布局替换为Fragment显示
4.1 代码
class MainActivity : AppCompatActivity() {
private val TAG_FLUTTER_FRAGMENT = “flutter_fragment”
private var flutterFragment: FlutterFragment?