问题描述
我有HomeActivity,其中包含片段,并且在底部具有自定义导航视图,如下所示.
I have HomeActivity which contains fragment and at the bottom it has custom navigation view as shown below.
通过单击配置文件图片,它将用UserProfileView片段替换该片段. userProfileView片段在coordinatorLayout内部具有Collapsing工具栏.
By clicking on profile pic, it replaces the fragment with UserProfileView fragment. userProfileView fragment has Collapsing toolbar inside coordinatorLayout.
userprofileview.xml
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>
问题是,当我从底部导航菜单中单击任何其他菜单时,它将滚动到屏幕,如下所示.
The problem is when i click to any other menu from bottom navigation menu, it scrolls off the screen as shown below.
在UserProfileView片段中添加CoordinatorLayout之后,就会发生此问题.
This issue is occurring after adding CoordinatorLayout in UserProfileView framgment.
如果我将Linear布局替换为CoordinatorLayout,则可以正常工作,但无法获得折叠工具栏的功能.
If i replace CoordinatorLayout with LinearLayout then it works fine but doesn't get the functionality of collapsing toolbar.
谢谢!
推荐答案
android:fitsSystemWindows="true"
会导致问题.简而言之...它可使您的抽屉布局全屏显示.
android:fitsSystemWindows="true"
in your fragment_user_profile.xml
causes problem. Simply... it makes your drawer layout looks fullscreen.
大致上,user
屏幕保持顶部指示器边距,而home
屏幕则没有.因此,主屏幕随指标大小而上升. (实际上不是,关于fitsSystemWindows的详细信息:我为什么要fitsSystemWindows )
Roughly, user
screen maintains top indicator margin and home
screen doesn't. So home screen moved up as indicator size. (Actually it isn't, Details about fitsSystemWindows:Why would I want to fitsSystemWindows)
因此,从fragment_user_profile.xml
删除fitsSystemWindows将解决您的问题.
So, remove fitsSystemWindows from fragment_user_profile.xml
will fix your problem.
我建议您将fitsSystemWindows
添加到activity_main.xml
中的container_body
中,但是我不确定实际的代码是什么,所以这就是您的要求.
And I suggest you add fitsSystemWindows
to your container_body
in activity_main.xml
, but I'm not sure that what is the actual code, so it is your call.
这篇关于在CoordinatorLayout中使用时,页脚在屏幕上滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!