작성
·
48
답변 2
0
activity_main.xml을 아래와 같이 변경해보시겠어요?
<?xml version="1.0" encoding="utf-8"?>
<layout>
<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">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/topBar"
android:layout_width="match_parent"
android:layout_height="60dp"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_margin="10dp"
android:src="@drawable/min_logo"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginTop="15dp"
android:layout_marginRight="20dp"
android:src="@drawable/main_menu"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0.5dp"
app:layout_constraintTop_toBottomOf="@+id/topBar"
android:background="#999999"
>
</LinearLayout>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentContainerView"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/main_nav"
android:layout_marginTop="60dp"
/>
<!-- <Button-->
<!-- android:id="@+id/logoutBtn"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="LOGOUT"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- app:layout_constraintLeft_toLeftOf="parent"-->
<!-- app:layout_constraintRight_toRightOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent" />-->
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
0
안녕하세요, 인프런 AI 인턴입니다. Mia님께서 겪고 계신 문제는 안드로이드 프래그먼트가 디자인 미리보기에서는 보이지만 실제 앱을 실행할 때는 보이지 않는 상황입니다. 이 문제의 일반적인 원인은 프래그먼트가 제대로 초기화되지 않거나 레이아웃이 올바르게 설정되지 않았을 때 발생할 수 있습니다.
아래의 게시물을 참조해 보시면 해결에 도움이 될 수 있습니다:
FragmentContainerView
를 활용한 프래그먼트 초기화 및 레이아웃 설정 관련 조언이 포함되어 있습니다.DataBindingUtil
을 사용하는 방법에 대한 추가 정보가 포함되어 있습니다.각 링크에서는 프래그먼트가 보이지 않는 문제를 다루고 있으며, 프래그먼트 초기화 및 레이아웃 문제를 진단하고 해결할 수 있는 방법들을 안내하고 있습니다.
다음 몇 가지 추가 팁을 드리자면:
FragmentTransaction
을 사용하고 있는지 확인하세요.FragmentManager
를 통해 정확한 방법으로 프래그먼트를 구성했는지 확인하세요.FragmentContainerView
의 아이디와 코드에서 사용하는 아이디가 일치하는지 확인해 보세요.저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다. 현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏 추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.
https://github.com/Passionhruit/my_solo_life
github 주소고 임시방편으로 MainActivity에 아래와같은 코드를 작성해서 해결하긴했습니다. 그렇지만 근본적인 문제가 뭔지 모르겠고, Device UI Shortcut 항목에서 폰트크기를 늘리는 등 ui를 변경하면 에뮬레이터에도 나타나긴합니다. 감사합니다
if (savedInstanceState == null) { // ✅ 앱이 처음 실행될 때만 Fragment 추가 supportFragmentManager.beginTransaction() .replace(R.id.fragmentContainerView, HomeFragment()) .commit() }