Skip to content

Commit d879ad4

Browse files
Merge pull request #99 from rive-app/update_fragment_example
Updates fragment example to use multiple fragments
2 parents 1f62c28 + 019c5e7 commit d879ad4

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

app/src/main/java/app/rive/runtime/example/RiveFragment.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.view.View
77
import android.view.ViewGroup
88
import androidx.fragment.app.Fragment
99
import app.rive.runtime.kotlin.RiveAnimationView
10+
import app.rive.runtime.kotlin.core.Fit
1011
import kotlin.properties.Delegates
1112

1213
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
@@ -41,6 +42,7 @@ class RiveFragment : Fragment() {
4142
override fun onViewStateRestored(savedInstanceState: Bundle?) {
4243
super.onViewStateRestored(savedInstanceState)
4344
riveView.setRiveResource(rId)
45+
riveView.fit = Fit.COVER
4446
}
4547

4648
override fun onDestroy() {

app/src/main/java/app/rive/runtime/example/RiveFragmentActivity.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,21 @@ class RiveFragmentActivity : AppCompatActivity() {
1212
super.onCreate(savedInstanceState)
1313
setContentView(R.layout.activity_rive_fragment)
1414

15-
// Instantiate a Rive fragment
16-
val bundle = bundleOf(RIVE_FRAGMENT_ARG_RES_ID to R.raw.basketball)
15+
// Instantiate the basketball fragment
16+
var bundle = bundleOf(RIVE_FRAGMENT_ARG_RES_ID to R.raw.basketball)
1717
if (savedInstanceState == null) {
1818
supportFragmentManager.commit {
1919
setReorderingAllowed(true)
20-
add<RiveFragment>(R.id.rive_fragment, args = bundle)
20+
add<RiveFragment>(R.id.basketball_fragment, args = bundle)
21+
}
22+
}
23+
24+
// Instantiate the flux fragment
25+
bundle = bundleOf(RIVE_FRAGMENT_ARG_RES_ID to R.raw.flux_capacitor)
26+
if (savedInstanceState == null) {
27+
supportFragmentManager.commit {
28+
setReorderingAllowed(true)
29+
add<RiveFragment>(R.id.flux_fragment, args = bundle)
2130
}
2231
}
2332
}

app/src/main/res/layout/activity_rive_fragment.xml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,26 @@
66
android:layout_height="match_parent"
77
tools:context=".MainActivity">
88

9-
10-
<androidx.fragment.app.FragmentContainerView
11-
xmlns:android="http://schemas.android.com/apk/res/android"
12-
android:id="@+id/rive_fragment"
9+
<ScrollView
1310
android:layout_width="match_parent"
14-
android:layout_height="match_parent" />
11+
android:layout_height="match_parent">
12+
13+
<LinearLayout
14+
android:layout_width="match_parent"
15+
android:layout_height="wrap_content"
16+
android:orientation="vertical">
17+
18+
<androidx.fragment.app.FragmentContainerView
19+
android:id="@+id/basketball_fragment"
20+
android:layout_width="match_parent"
21+
android:layout_height="match_parent" />
1522

23+
<androidx.fragment.app.FragmentContainerView
24+
android:id="@+id/flux_fragment"
25+
android:layout_width="match_parent"
26+
android:layout_height="match_parent" />
1627

28+
</LinearLayout>
29+
</ScrollView>
1730

1831
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)