From 6c916671aa051d244d01f4e86de5467d30d8a320 Mon Sep 17 00:00:00 2001 From: jafu888 Date: Thu, 10 Jun 2021 17:06:59 -0700 Subject: [PATCH] make main ui cycle through composable --- .../example/constraintlayout/MainActivity.kt | 59 +++++++++++++++++-- .../app/src/main/res/layout/activity_main.xml | 52 +++++++++++++--- 2 files changed, 98 insertions(+), 13 deletions(-) diff --git a/projects/ComposeConstraintLayout/app/src/main/java/com/example/constraintlayout/MainActivity.kt b/projects/ComposeConstraintLayout/app/src/main/java/com/example/constraintlayout/MainActivity.kt index d9b2aea35..ce8cb0cb6 100644 --- a/projects/ComposeConstraintLayout/app/src/main/java/com/example/constraintlayout/MainActivity.kt +++ b/projects/ComposeConstraintLayout/app/src/main/java/com/example/constraintlayout/MainActivity.kt @@ -1,15 +1,62 @@ package com.example.constraintlayout -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import androidx.activity.compose.setContent -import androidx.constraintlayout.compose.ScreenExample6 +import android.view.View +import android.widget.FrameLayout +import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity +import androidx.compose.ui.platform.ComposeView +import androidx.constraintlayout.compose.* class MainActivity : AppCompatActivity() { + private var mFrameLayout: FrameLayout? = null + private var composeNum = 6 + private var MAX = 12 + + private fun show(com: ComposeView) { + com.setContent() { + when (composeNum) { + 0 -> ScreenExample() + 1 -> ScreenExample() + 2 -> ScreenExample2() + 3 -> ScreenExample3() + 4 -> ScreenExample4() + 5 -> ScreenExample5() + 6 -> ScreenExample6() + 7 -> ScreenExample7() + 8 -> ScreenExample8() + 9 -> ScreenExample9() + 10 -> ScreenExample10() + 11 -> ScreenExample11() + } + } + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContent { - ScreenExample6() + setContentView(R.layout.activity_main) + mFrameLayout = findViewById(R.id.frame) + setCompose(); + } + + fun setCompose() { + if (mFrameLayout!!.childCount > 0) { + mFrameLayout!!.removeAllViews() } + title = " example " + composeNum; + findViewById(R.id.layoutName).text = " example " + composeNum; + var com = ComposeView(this); + mFrameLayout!!.addView(com) + show(com) + } + + fun prev(view: View) { + composeNum = (composeNum + MAX - 1) % MAX + setCompose() + } + + fun next(view: View) { + composeNum = (composeNum + 1) % MAX + setCompose(); } -} \ No newline at end of file +} diff --git a/projects/ComposeConstraintLayout/app/src/main/res/layout/activity_main.xml b/projects/ComposeConstraintLayout/app/src/main/res/layout/activity_main.xml index e8e272692..425f6615b 100644 --- a/projects/ComposeConstraintLayout/app/src/main/res/layout/activity_main.xml +++ b/projects/ComposeConstraintLayout/app/src/main/res/layout/activity_main.xml @@ -3,17 +3,55 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="wrap_content" + android:layout_height="match_parent" + app:layout_optimizationLevel="none" + android:background="#D9A" tools:context=".MainActivity"> - + + + + +