【问题标题】:fitsSystemWindows does not work in added fragmentfitSystemWindows 在添加的片段中不起作用
【发布时间】:2017-08-31 20:28:55
【问题描述】:

在我的应用中,我有一个活动。此活动的主题是正常的 pre-L,但在 L 及更高版本中被覆盖,带有:

...
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@color/statusTrans</item>
...

此活动具有这样的布局(fsw 表示该节点适合SystemWindows)以提供材质效果。

CoordinatorLayout (fsw)
  L AppBarLayout (fsw)
      L CollapsingToolbarLayout (fsw)
          L ImageView (fsw)
          L Toolbar
      L TabLayout
  L ViewPager
  L FAB

问题是,我通过事务将全屏DialogFragment 添加到此活动中,方法是将其添加到具有此布局的 android.R.id.content 中

CoordinatorLayout (fsw)
  L AppBarLayout (fsw)
      L CollapsingToolbarLayout (fsw)
          L FrameLayout
          L Toolbar
      L TabLayout
  L NestedScrollView

初始布局按预期绘制状态栏,然后在其下方绘制Toolbar(即应用插图),但添加的片段布局直接在状态栏下方绘制Toolbar,我似乎无法让它正确绘制.

我不知道我做错了什么。这是显示问题的两个屏幕截图。

.

还有(奖励问题!)

在同一个 Activity 中,我将 Viewpager 设置为具有 ScrollingViewBehavior。 然而,填充Viewpager 的片段有一个ViewFlipper,它会切换其中之一:loadingView(ProgressBar)、contentView(RecyclerView) 和 emptyView(LinearLayout)。 这样可以确保如果有内容,则 Activity 具有所需的滚动效果。

emptyView 出现问题,因为它没有正确居中。我附上了一张图片。

如何纠正(或破解)这种行为?

【问题讨论】:

  • 您好,您找到解决方案了吗?我现在也有同样的问题:(

标签: android android-fragments androiddesignsupport


【解决方案1】:

无论您在哪里替换片段,请确保其处于协调器布局中。例如,如果您的 xml 如下所示:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:ignore="MissingPrefix">

    <FrameLayout
        android:id="@+id/fl_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

然后将其包装在 coordinatorlayout 中以解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-16
    • 1970-01-01
    • 2019-02-13
    • 2017-05-15
    • 2016-07-16
    • 2020-05-27
    • 1970-01-01
    相关资源
    最近更新 更多