BottomAppBar被推离屏幕 [英] BottomAppBar being pushed off screen
问题描述
当我使用底部的应用程序栏从任何片段切换回购物清单时,它会被推离屏幕,我也不知道为什么.在冰箱片段"和食品间片段"之间切换很有效,但是从其中一个切换回购物清单片段"会将栏推离屏幕,如下所示:
When I switch from any fragment back to Shopping List with the bottom app bar, it gets pushed down off the screen and I don't know why. Switching between the Fridge Fragment and Pantry Fragment works great, but switching from either of those back to the Shopping List Fragment pushes the bar off the screen, as shown here:
推荐答案
尝试对FrameLayout
进行这些更改,我想之后您将不需要fragment_navigation.xml
.
Try with these changes for FrameLayout
and I guess you won't need fragment_navigation.xml
after that.
activity_main.xml
:
activity_main.xml
:
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/relative_layout_for_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_app_bar"
style="@style/Widget.MaterialComponents.BottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar"
app:backgroundTint="@color/colorPrimary"
app:hideOnScroll="true"
app:layout_scrollFlags="scroll|enterAlways"
app:navigationIcon="@drawable/ic_menu_white_24dp" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_shopping_cart_white_24dp"
app:fabSize="normal"
app:layout_anchor="@id/bottom_app_bar" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
您还说过,当您切换到具有其中的另一个CoordinatorLayout
.
You also said that it happens when you switch to ShoppingListFragment
which has another CoordinatorLayout
in there.
您只需更改fragment_shopping_list.xml
代码,如下所示:
You simply change fragment_shopping_list.xml
codes as follows:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/shopping_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="141dp"
android:text="TextView" />
</RelativeLayout>
或者只是不要在其中使用CoordinatorLayout
,然后尝试.
Or just don't use CoordinatorLayout
in there then try.
这篇关于BottomAppBar被推离屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!