안드로이드용 Qt Quick 을 사용한 안드로이드 프래그먼트
ViewGroup 기반 객체를 사용하여 안드로이드 UI 레이아웃에 QtQuickView를 가질 수 있습니다. 여기서는 프레임 레이아웃을 사용하겠습니다.
QtQuickView API에 익숙하지 않은 경우 이 튜토리얼을 계속하기 전에 해당 문서를 읽어보시기 바랍니다.
계속 진행하기 전에 Qt 아카데미 강좌인 '안드로이드 앱에 콘텐츠 임베딩하기( Qt Quick 3D )'를 살펴보는 것이 좋습니다.
시작하려면 Bottom Navigation Views Activity 템플릿을 사용하여 안드로이드 스튜디오에서 새 프로젝트를 생성합니다.
- QtQuickView를 표시할 프래그먼트 또는 액티비티를 찾습니다. 여기서는
HomeFragment
과fragment_home.xml
을 사용합니다. fragment_home.xml
에서 프레임레이아웃을 생성하고id
을 아래와 같이 설정합니다.<FrameLayout android:id="@+id/homeQmlFrame" android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHeight_percent="0.8"/>
레이아웃을 바인딩할 때
HomeFragment
에서 참조해야 하므로 이 ID를 기록해 두세요.- HomeFragment.kt 내에서 FrameLayout에 대한 import 문을 추가합니다:
import android.widget.FrameLayout
- QtQuickView 및 Screen01 QML 유형에 대한 임포트를 추가하고 클래스 내부에 선언합니다:
import org.qtproject.qt.android.QtQuickView import org.qtproject.example.RoboApp.RoboContent.Screen01 class HomeFragment : Fragment() { private var binding: FragmentHomeBinding? = null private lateinit var homeQmlContent: Screen01 private lateinit var homeQtQuickView: QtQuickView
- QtQuickView를 할당하고 다음을 사용하여 Activity 인스턴스를 지정합니다.
requireActivity()
homeQtQuickView = QtQuickView(requireActivity()) homeQmlContent = Screen01()
- 레이아웃 파라미터를 초기화하고, 프로그래밍 방식으로 뷰를 생성하는 경우 뷰를 동적으로 추가하거나 런타임에 변경합니다. 그렇지 않으면 이 섹션을 건너뛸 수 있으며
params
와addView()
을 사용할 필요가 없습니다.val params = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
- 를 사용하여 레이아웃에 보기를 추가합니다:
onCreateView()
내에서 뷰 바인딩 사용: 먼저 앱의 build.gradle.kts 안드로이드 섹션에buildFeature
섹션을 추가하여 뷰 바인딩이 활성화되어 있는지 확인합니다:buildFeatures { viewBinding = true }
그런 다음
onCreateView()
에 다음을 추가합니다:binding = FragmentHomeBinding.inflate( inflater, container, false) homeQtQuickView.loadContent(homeQmlContent) val root: View = binding.root binding.homeQmlFrame.addView(homeQtQuickView, params) ... return root
onCreate()
안에findViewById()
사용val qtFrame = findViewById(R.id.qtFrame) qmlFrame.addView(m_quickView, params) m_quickView.loadContent(homeQmlContent)
이제 Qt Quick 콘텐츠가 홈 조각에 표시됩니다.
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.