【问题标题】:footer scrolls off screen when used in CoordinatorLayout在 CoordinatorLayout 中使用时页脚滚动到屏幕外
【发布时间】:2018-04-23 14:46:48
【问题描述】:

我有 HomeActivity,其中包含片段,底部有自定义导航视图,如下所示。

通过点击个人资料图片,它将片段替换为 UserProfileView 片段。 userProfileView 片段在 coordinatorLayout 中有折叠工具栏。

userprofileview.xml

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:bind="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <data>

        <variable
            name="resource"
            type="com.example.app.model.ResourceData" />


        <import type="android.view.View" />

    </data>

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/bg_home"
        android:fitsSystemWindows="true">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/bg_home">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/toolbar_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">


                </LinearLayout>
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/_10sdp"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/ic_list"
                    android:layout_width="@dimen/_17sdp"
                    android:layout_height="@dimen/_17sdp"
                    android:layout_gravity="center"
                    android:layout_marginLeft="@dimen/_10sdp"
                    android:background="@drawable/ic_list_selected" />

                <ImageView
                    android:id="@+id/ic_grid_view"
                    android:layout_width="@dimen/_15sdp"
                    android:layout_height="@dimen/_15sdp"
                    android:layout_gravity="center"
                    android:layout_marginLeft="@dimen/_10sdp"
                    android:background="@drawable/ic_grid_unselected" />
            </LinearLayout>

            <android.support.v7.widget.RecyclerView
                android:visibility="gone"
                android:id="@+id/rv_post"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:resource="@{resource}" />

        </LinearLayout>
    </android.support.design.widget.CoordinatorLayout>
</layout>

问题是当我从底部导航菜单单击任何其他菜单时,它会滚动到屏幕外,如下所示。

在 UserProfileView 框架中添加 CoordinatorLayout 后出现此问题。

如果我用 LinearLayout 替换 CoordinatorLayout 那么它工作正常,但没有得到折叠工具栏的功能。

谢谢!

【问题讨论】:

  • 我认为您在这里描述的场景类似于the issue here,所以我建议尝试在那里实施最近的解决方案之一
  • @NoaDrach 我试过了,还在那里评论了我的问题。谢谢。
  • 你能在 github 上发布一个具有这种行为的简单项目吗?
  • 是的。 github.com/chetanparmar95/TestApp。我也使用了“Theme.AppCompat.Light.NoActionBar”主题,但如果我使用 DarkActionBar 而不是 NoActionBar,那么它可以正常工作,但 ActionBar 的下降方式与 BottomView 的移动方式相同

标签: android android-layout android-fragments android-coordinatorlayout android-collapsingtoolbarlayout


【解决方案1】:

android:fitsSystemWindows="true" 中的 fragment_user_profile.xml 会导致问题。简单...它使您的抽屉布局看起来全屏。

大致上,user 屏幕保持顶部指示器边距,home 屏幕没有。所以主屏幕向上移动作为指标大小。 (其实不是,关于fitsSystemWindows的详细信息: Why would I want to fitsSystemWindows)

所以,从fragment_user_profile.xml 中删除 fitSystemWindows 将解决您的问题。

我建议您在activity_main.xml 中将fitsSystemWindows 添加到您的container_body,但我不确定实际代码是什么,所以这是您的电话。

【讨论】:

    猜你喜欢
    • 2015-08-26
    • 2015-10-04
    • 2017-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-14
    • 1970-01-01
    相关资源
    最近更新 更多