마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

액션 바에 대해 질문드립니다!

0 추천
메뉴 하단에 bottom navigation bar를 추가했는데 위에 액션 바 때문인지 상단에 있던 버튼이 내려가서

아래와 겹쳐져 보이지 않더라구요...?

어떻게 하는지 아시는 분 계시면 알려주시면 감사하겠습니다..

(사진을 첨부하고 싶은데 용량이 안 된다고 하네요ㅠㅠ)
탁구왕김제빵 (240 포인트) 님이 2022년 10월 5일 질문
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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?attr/actionBarSize"
    android:background = "@color/colorBackground">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="@id/nav_view"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_nav_menu" />

    <fragment
        android:id="@+id/nav_host_fragment_activity_main"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@id/nav_view"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/mobile_navigation" />

<LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        tools:layout_editor_absoluteY="5dp">

        <Button
            android:id="@+id/courseButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="5dp"
            android:layout_weight="1"
            android:background="@color/colorPrimary"
            android:text="강의 목록"
            android:textColor="#FFFFFF"
            android:textSize="18dp"
            android:textStyle="bold" />

        <Button
            android:id="@+id/scheduleButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:layout_weight="1"
            android:background="@color/colorPrimary"
            android:text="시간표"
            android:textColor="#FFFFFF"
            android:textSize="18dp"
            android:textStyle="bold" />

        <Button
            android:id="@+id/statisticsButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:layout_weight="1"
            android:background="@color/colorPrimary"
            android:text="강의 분석"
            android:textColor="#FFFFFF"
            android:textSize="18dp"
            android:textStyle="bold" />


        <Button
            android:id="@+id/calendarButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:layout_weight="1"
            android:background="@color/colorPrimary"
            android:text="일정 정리"
            android:textColor="#FFFFFF"
            android:textSize="18dp"
            android:textStyle="bold" />

    </LinearLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            app:layout_constraintTop_toTopOf="parent"
            android:id="@+id/notice">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:orientation="vertical"
                android:background="@color/colorPrimary"
                android:layout_marginTop="5dp">

                <ImageButton
                    android:layout_width="125dp"
                    android:layout_height="125dp"
                    android:layout_gravity="center"
                    android:layout_marginTop="10dp"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:text="공지사항"
                    android:textColor="#ffffff"
                    android:textSize="25dp"
                    android:textStyle="bold"
                    android:layout_marginTop="10dp"/>

            </LinearLayout>

            <ListView
                android:id="@+id/noticeListView"
                android:layout_width="match_parent"
                android:layout_height="457dp"
                android:layout_margin="10dp"
                android:divider="#ffffff"
                android:dividerHeight="10dp"></ListView>

        </LinearLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/fragment">
        </RelativeLayout>

    </FrameLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

3개의 답변

0 추천
레이아웃 파일을 볼 수 없어서 추측으로 말씀드릴게요.ConstraintLayout을 사용하신다면, layout_height를 0dp로 주시고 BottomTop constraint가 BottomNavigationView를 가리키도록 해주세요.

android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/ bottomnavigationviewid"
spark (224,800 포인트) 님이 2022년 10월 6일 답변
0 추천

문제 해결은 다른 답글에서 말씀드린대로 관련된 뷰의 Constraint를 설정함으로써 해결이 가능합니다.

<com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_nav_menu" />

    <fragment
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@id/nav_view"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/mobile_navigation" />

 

추가로 fragment 대신에 FragmentContainerView를 사용하는건 권장하는게 구글의 입장입니다. 라이브러리 개발자의 트윗에 이유가 나옵니다. https://twitter.com/ianhlake/status/1220050760802566144

FragmentContainterView를 사용하면 아래처럼 navigation controller를 찾는 코드를 수정하면 됩니다.
 

NavHostFragment navHostFragment =
            (NavHostFragment) supportFragmentManager.findFragmentById(R.id.nav_host_fragment) 
navHostFragment.getNavController();

 

여담이지만, 레이아웃이 많이 복잡해 보이네요. 상단의 공지사항 부분의 컨트롤도 복잡해질 듯합니다.

spark (224,800 포인트) 님이 2022년 10월 7일 답변
spark님이 2022년 10월 7일 수정
아~ 감사합니다!!
상단 공지사항 때문에 지금 상당히 골치 아픕니다...하하
공지사항이 항상 상단에 고정되어 있어야 한다면 ColapsingToolbar, CoordinateLayout을 사용하는 걸 고려해 보시는게 좋을 것 같습니다. 공지사항은 MainActivity에 MainViewModel을 연결해서 거기서 업데이트 하시구요. 만약 다른 프레그먼트에서도 공지사항을 접근해야 한다면, MainViewModel을 공유하면 되구요.
아...제가 상단에 버튼을 놓아야 하는데 공지사항이 버튼을 가리는 상황입니다...
아무튼 감사합니다!!
0 추천
<?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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?attr/actionBarSize"
    android:background = "@color/colorBackground">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="@id/nav_view"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_nav_menu" />

    <fragment
        android:id="@+id/nav_host_fragment_activity_main"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@id/nav_view"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/mobile_navigation" />
layout 코드입니다! 님이 2023년 3월 2일 답변
...