android BottomNavigation与DrawerLayout中的FrameLayout内容重叠

vof42yt1  于 2023-06-27  发布在  Android
关注(0)|答案(1)|浏览(152)

FrameLayout中的每个底部内容都隐藏在bottomNavigation后面,下面是我的代码.....我正在制作一个有点复杂的应用程序,它具有抽屉布局和bottomnavigation,我也使用framelayout来显示不同的片段,当菜单项从底部导航单击时,问题是我是否使用constraintLayout或线性布局(不作为rootlayout)而不是FrameLayout和bottomNavigation上方的RelativeLayout它仍然隐藏我的所有片段底部内容,无论是recyclerview还是button

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <androidx.drawerlayout.widget.DrawerLayout
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. xmlns:app="http://schemas.android.com/apk/res-auto"
  5. xmlns:tools="http://schemas.android.com/tools"
  6. android:id="@+id/drawerLayoutID"
  7. android:layout_width="match_parent"
  8. android:layout_height="match_parent"
  9. tools:context=".MainActivity">
  10. <RelativeLayout
  11. android:layout_width="match_parent"
  12. android:layout_height="match_parent">
  13. <FrameLayout
  14. android:id="@+id/frame_container"
  15. android:layout_width="match_parent"
  16. android:layout_height="match_parent"
  17. app:layout_behavior="@string/appbar_scrolling_view_behavior" />
  18. <com.google.android.material.bottomnavigation.BottomNavigationView
  19. android:id="@+id/bottom_navigation_ID"
  20. android:layout_width="match_parent"
  21. android:layout_height="wrap_content"
  22. android:layout_alignParentBottom="true"
  23. android:layout_gravity="bottom|end"
  24. android:background="?android:attr/windowBackground"
  25. app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
  26. android:foreground="?attr/selectableItemBackground"
  27. app:itemIconTint="@color/bottom_navigation_color"
  28. app:labelVisibilityMode="unlabeled"
  29. app:menu="@menu/navigation"/>
  30. </RelativeLayout>
  31. <RelativeLayout
  32. android:layout_width="match_parent"
  33. android:layout_height="match_parent"
  34. android:layout_gravity="start"
  35. android:id="@+id/checkCon"
  36. android:layout_weight="1"
  37. android:background="@color/navyBlue">
  38. <RelativeLayout
  39. android:layout_width="match_parent"
  40. android:layout_height="match_parent"
  41. android:layout_weight="1"
  42. android:background="@color/favoriteColor">
  43. <EditText
  44. android:id="@+id/search_editText_id"
  45. android:layout_width="match_parent"
  46. android:layout_height="wrap_content"
  47. android:layout_marginStart="16dp"
  48. android:layout_marginTop="24dp"
  49. android:layout_marginEnd="16dp"
  50. android:background="@drawable/rounded_corner_backgrond"
  51. android:hint="@string/search"
  52. android:paddingLeft="10dp"
  53. android:paddingBottom="10dp"
  54. android:paddingTop="10dp"/>
  55. <Button
  56. android:layout_width="wrap_content"
  57. android:layout_height="wrap_content"
  58. android:id="@+id/all_button_id"
  59. android:layout_below="@id/search_editText_id"
  60. android:textColor="@color/whiteColor"
  61. android:text="@string/selectAll"
  62. android:textAllCaps="false"
  63. android:layout_marginTop="10dp"
  64. android:layout_centerHorizontal="true"
  65. android:background="@android:color/transparent"/>
  66. <androidx.recyclerview.widget.RecyclerView
  67. android:id="@+id/search_RecylerView"
  68. android:layout_width="match_parent"
  69. android:layout_height="match_parent"
  70. android:layout_below="@+id/all_button_id" />
  71. </RelativeLayout>
  72. </RelativeLayout>
  73. </androidx.drawerlayout.widget.DrawerLayout>
1aaf6o9v

1aaf6o9v1#

您只需将框架布局的底部约束提供给底部导航的顶部,这样框架布局的底部内容就不会隐藏在底部导航后面。
参考此代码将解决您的挑战。

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:id="@+id/drawerLayoutID"
  6. android:layout_width="match_parent"
  7. android:layout_height="match_parent"
  8. tools:context=".MainActivity">
  9. <!-- i just changed here to constraint layout from the relative layout.-->
  10. <androidx.constraintlayout.widget.ConstraintLayout
  11. android:layout_width="match_parent"
  12. android:layout_height="match_parent"
  13. android:background="@drawable/ic_setting_background">
  14. <FrameLayout
  15. android:id="@+id/frame_container"
  16. android:layout_width="match_parent"
  17. android:layout_height="0dp"
  18. app:layout_constraintTop_toTopOf="parent"
  19. app:layout_constraintBottom_toTopOf="@id/bottom_navigation_ID"
  20. android:background="@color/black"
  21. app:layout_behavior="@string/appbar_scrolling_view_behavior" />
  22. <com.google.android.material.bottomnavigation.BottomNavigationView
  23. android:id="@+id/bottom_navigation_ID"
  24. android:layout_width="match_parent"
  25. app:layout_constraintBottom_toBottomOf="parent"
  26. android:layout_height="wrap_content"
  27. android:layout_alignParentBottom="true"
  28. android:layout_gravity="bottom|end"
  29. android:background="?android:attr/windowBackground"
  30. android:foreground="?attr/selectableItemBackground"
  31. app:itemIconTint="@color/bottom_navigation_color"
  32. app:labelVisibilityMode="unlabeled"
  33. app:menu="@menu/navigation"
  34. app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior" />
  35. </androidx.constraintlayout.widget.ConstraintLayout>
  36. <RelativeLayout
  37. android:id="@+id/checkCon"
  38. android:layout_width="match_parent"
  39. android:layout_height="match_parent"
  40. android:layout_gravity="start"
  41. android:layout_weight="1"
  42. android:background="@color/navyBlue">
  43. <RelativeLayout
  44. android:layout_width="match_parent"
  45. android:layout_height="match_parent"
  46. android:layout_weight="1"
  47. android:background="@color/favoriteColor">
  48. <EditText
  49. android:id="@+id/search_editText_id"
  50. android:layout_width="match_parent"
  51. android:layout_height="wrap_content"
  52. android:layout_marginStart="16dp"
  53. android:layout_marginTop="24dp"
  54. android:layout_marginEnd="16dp"
  55. android:background="@drawable/rounded_corner_backgrond"
  56. android:hint="@string/search"
  57. android:paddingLeft="10dp"
  58. android:paddingTop="10dp"
  59. android:paddingBottom="10dp" />
  60. <Button
  61. android:id="@+id/all_button_id"
  62. android:layout_width="wrap_content"
  63. android:layout_height="wrap_content"
  64. android:layout_below="@id/search_editText_id"
  65. android:layout_centerHorizontal="true"
  66. android:layout_marginTop="10dp"
  67. android:background="@android:color/transparent"
  68. android:text="@string/selectAll"
  69. android:textAllCaps="false"
  70. android:textColor="@color/whiteColor" />
  71. <androidx.recyclerview.widget.RecyclerView
  72. android:id="@+id/search_RecylerView"
  73. android:layout_width="match_parent"
  74. android:layout_height="match_parent"
  75. android:layout_below="@+id/all_button_id" />
  76. </RelativeLayout>
  77. </RelativeLayout>
  78. </androidx.drawerlayout.widget.DrawerLayout>
展开查看全部

相关问题