【发布时间】:2021-01-20 02:23:08
【问题描述】:
我有一个双摄像头活动的实现作为 Android Kotlin 项目。我想在颤振中使用相同的双摄像头,因为颤振没有任何用于双摄像头功能的库。
我曾尝试使用平台通道来做这件事,但事实证明平台通道只是用于颤振和原生平台之间的消息传递。我不只是想传递消息,我希望将一个 android 项目的片段/活动包含为一个颤振小部件,我可以在任何我想要的地方使用它。
基本上,有一个 Android 活动,其中有一些与之关联的 Kotlin 代码。我希望所有这些都在 Flutter 中工作并与之通信,包括 XML 前端和 Kotlin 后端。我在此处附上我的 xml 文件以供参考。代码文件只是填充 xml 组件。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<SurfaceView
android:id="@+id/surfaceView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.2" />
<SurfaceView
android:id="@+id/surfaceView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="-65dp"
android:layout_weight="1" />
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxHeight="30dp"
android:src="@drawable/ic_inclinedline"/>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
【问题讨论】:
-
我以前从未这样做过,但我认为这是不可能的,因为颤振与 android 不同。它确实将其源代码编译为原生 android 代码,但它也将自己的框架和其他功能编译为原生 android 代码。这似乎是一种单向编译。
-
您也可以保留您的应用并为其添加 Flutter。 flutter.dev/docs/development/….
-
@Rolly 安卓应用是可能的,但是我们的应用已经是一个颤振应用了。
标签: android flutter android-layout kotlin flutter-layout