Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<FrameLayout>(R.id.frame)
setCompose();
}

fun setCompose() {
if (mFrameLayout!!.childCount > 0) {
mFrameLayout!!.removeAllViews()
}
title = " example " + composeNum;
findViewById<TextView>(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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<TextView
<FrameLayout
android:id="@+id/frame"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="2dp"
android:background="#0F0"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/prev">


</FrameLayout>

<Button
android:id="@+id/prev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00BCD4"
android:text="Hello World!"
android:text="prev"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:onClick="prev" />

<Button
android:id="@+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="next"
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintEnd_toEndOf="parent"
android:onClick="next" />

<TextView
android:id="@+id/layoutName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Hello World!"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="@+id/prev"
app:layout_constraintStart_toEndOf="@+id/prev"
app:layout_constraintEnd_toStartOf="@+id/next"
app:layout_constraintTop_toTopOf="@+id/prev" />


</androidx.constraintlayout.widget.ConstraintLayout>