【问题标题】:BottomAppBar being pushed off screenBottomAppBar 被推离屏幕
【发布时间】:2018-10-22 18:40:13
【问题描述】:

当我使用底部应用栏从任何片段切换回购物清单时,它会被推下屏幕,我不知道为什么。在 Fridge Fragment 和 Pantry Fragment 之间切换效果很好,但是从其中任何一个切换回 Shopping List Fragment 都会将栏推离屏幕,如下所示:

Github repository with full code

【问题讨论】:

  • 您是否尝试运行层次结构查看器来查看您的布局层次结构? developer.android.com/training/improving-layouts/…
  • 有几件事跳出来——在 fragment_shopping_list.xml 文件中你没有实现android:fitsSystemWindows="true"——我也不认为CoordinatorLayout 有一个orientation 属性。跨度>

标签: android android-layout material-design


【解决方案1】:

尝试对FrameLayout 进行这些更改,我想在那之后您将不再需要fragment_navigation.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>

您还说过,当您切换到其中有another CoordinatorLayoutShoppingListFragment 时,就会发生这种情况。

您只需将fragment_shopping_list.xml 代码更改如下:

<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然后尝试。

【讨论】:

  • 感谢您的关注,我实施了这些更改,以及@Barns 建议的更改,但它仍在发生。更新代码已推送,想看的可以查看
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多