【问题标题】:Android fragment getting hidden under the action barAndroid片段隐藏在操作栏下
【发布时间】:2014-07-21 09:54:29
【问题描述】:

遇到了一个奇怪的问题。片段的内容隐藏在操作栏下。它是一个非常基本的抽屉布局和一个片段。

android新手,不知道是不是这样。 我使用边距只是为了将其拉低,如下所示。但这对我来说听起来不正确......请指出我哪里出错了。提前致谢。

【问题讨论】:

  • 你在使用 ACTION_BAR_OVERLAY 标志吗?
  • 天哪……是的! android:windowActionBarOverlay 设置为 true... 非常感谢。请将此添加为我会接受的答案。 @blackbelt
  • @Mouli :我知道这篇文章更新已经很久了。但我现在有同样的问题。我在我的styles.xml 中添加了 android:windowActionBarOverlay 为 false,但 textview 的一部分仍然隐藏在我的操作栏后面。我是在正确的地方添加它还是应该在其他地方添加它。请帮忙
  • 您的内容是否可能包含在滚动视图中,开始“滚动”内容?

标签: android android-fragments


【解决方案1】:

添加属性 app:layout_behavior="@string/appbar_scrolling_view_behavior" 到你的片段的父视图。

【讨论】:

    【解决方案2】:

    如果您设置 FEATURE_ACTION_BAR_OVERLAY (android:windowActionBarOverlay) ,这是正常和预期的行为。 Here文档

    【讨论】:

    • 我知道这篇文章更新已经很久了。但我现在有同样的问题。我在我的styles.xml 中添加了 android:windowActionBarOverlay 为 false,但 textview 的一部分仍然隐藏在我的操作栏后面。我是在正确的地方添加它还是应该在其他地方添加它。请帮忙
    • 你在使用 CoordinatorLayout 吗?
    • 是的。应用栏的 CoordinatorLayout。我正在为我的项目使用 android 的默认“导航抽屉”活动。当我添加片段时,部分文本视图隐藏在操作栏后面
    • 非常感谢。我可以通过添加 "@string/appbar_scrolling_view_behavior" 来修复它。再次感谢
    【解决方案3】:

    对于许多看到此问题的人来说,另一种可能的解决方案是将工具栏的父布局更改为 LinearLayout(可能是垂直方向),因为这种布局不允许其子级重叠。

    例如,activity_main.xml 中的这种布局将导致片段位于工具栏下方,而不是在其后面:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical">
    
        <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"/>
        </com.google.android.material.appbar.AppBarLayout>
    
        <FrameLayout
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".MainActivity">
    
            <androidx.fragment.app.FragmentContainerView
                android:id="@+id/nav_host_fragment"
                android:name="androidx.navigation.fragment.NavHostFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:defaultNavHost="true"
                app:navGraph="@navigation/nav_graph"/>
        </FrameLayout>
    </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-18
      • 1970-01-01
      • 2013-06-21
      • 1970-01-01
      相关资源
      最近更新 更多