Skip to content

Add Scene via XML

qiibeta edited this page Oct 29, 2019 · 9 revisions

ScenePlaceHolderView

Add Scene via XML can reduce view hierarchy, ScenePlaceHolderView will be replace by Scene created view.

XML

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:app="http://schemas.android.com/apk/res-auto"
             android:layout_width="match_parent"
             android:layout_height="match_parent">
 
    <...>
    
    <...>

    <com.bytedance.scene.group.ScenePlaceHolderView
        app:name="com.bytedance.scenedemo.group.EmptyScene"
        app:tag="TAG"
        android:id="@+id/scene"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</FrameLayout>

Before GroupScene enter onActivityCreated(), all ScenePlaceHolderViews will be replace to target Scene's view instance

Arguments

Add these codes to GroupScene onViewCreated() method

val bundle = Bundle()
val placeHolderView = requireViewById<ScenePlaceHolderView>(R.id.scene)
placeHolderView.arguments = bundle

Proguard