看板 AndroidDev 關於我們 聯絡資訊
AndroidX可以透過 app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScr ol 在滑動時隱藏或顯示BottomNavigation 但我在嘗試的時候並不是這麼順利,也確定在XML當中的元件都是在CoordinatorLayout當 中 附上源碼 //activty_main.xml <?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://sch em 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" tools:context=".MainActivity"> <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/nav_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:background="?android:attr/windowBackground" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_behavior="com.google.android.material.behavior.HideBottomVi ew app:menu="@menu/bottom_nav_menu" /> <fragment android:id="@+id/nav_host_fragment_activity_main" android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" 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" /> </androidx.coordinatorlayout.widget.CoordinatorLayout> //fragement_dashboard.xml <?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout 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" android:background="#f1f5f7" tools:context=".ui.dashboard.DashboardFragment"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:layout_marginBottom="50dp" app:layout_constraintTop_toTopOf="parent"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingTop="0dp" android:text="New Release Films" android:textColor="#111" android:textSize="16dp" /> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:clipToPadding="false" android:scrollbars="vertical" /> </LinearLayout> <com.google.android.material.bottomnavigation.BottomNavigationView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" app:menu="@menu/bottom_nav_menu" app:layout_behavior="com.google.android.material.behavior.HideBottomVi ew </com.google.android.material.bottomnavigation.BottomNavigationView> </androidx.coordinatorlayout.widget.CoordinatorLayout> 我也確保編譯器的版本在3.4以上 想請問版上有任何大大有遇到類似的問題嗎? -- Sent from my Windows -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.43.102.15 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1631384791.A.83B.html ※ 編輯: lee16818 (223.137.131.164 臺灣), 09/12/2021 13:46:35