Android 正在将Viewpager推出屏幕[CoordinatorLayout][Design Library]
我有一个简单的应用程序,带有一个包含3个片段的viewpager。在其中一个片段中,我有一个Recyclerview列表。向下滚动时,工具栏折叠,向上滚动时显示。我的问题是,当工具栏折叠,我向左/向右滚动时,我会以编程方式展开它,它会向下推动viewpager,而不是重叠它。这会导致屏幕视图出现不令人满意的位移。如何使工具栏与viewpager重叠,而不是在展开时向下推? 我对这个问题做了一个简短的记录 这是我的主要布局:Android 正在将Viewpager推出屏幕[CoordinatorLayout][Design Library],android,android-fragments,android-viewpager,android-recyclerview,android-coordinatorlayout,Android,Android Fragments,Android Viewpager,Android Recyclerview,Android Coordinatorlayout,我有一个简单的应用程序,带有一个包含3个片段的viewpager。在其中一个片段中,我有一个Recyclerview列表。向下滚动时,工具栏折叠,向上滚动时显示。我的问题是,当工具栏折叠,我向左/向右滚动时,我会以编程方式展开它,它会向下推动viewpager,而不是重叠它。这会导致屏幕视图出现不令人满意的位移。如何使工具栏与viewpager重叠,而不是在展开时向下推? 我对这个问题做了一个简短的记录 这是我的主要布局: <android.support.design.widget.C
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".UI.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/appBarLayouy"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="@dimen/tabsHeight"
style="@style/NavigationTab"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<include layout="@layout/content_main"/>
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="@+id/floatingActionMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
fab:fab_addButtonColorNormal="@color/blood_orange"
fab:fab_addButtonColorPressed="@color/dirtyWhite"
fab:fab_addButtonPlusIconColor="@color/dirtyWhite"
fab:fab_addButtonSize = "normal"
fab:fab_labelStyle="@style/menu_labels_style"
fab:fab_labelsPosition="left"
app:layout_anchor="@id/viewpager"
app:layout_anchorGravity="bottom|end">
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/createPlanBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/blood_orange"
fab:fab_title="Create a plan"
fab:fab_size="normal"
app:fab_icon="@drawable/ic_event_white_48dp"
fab:fab_colorPressed="@color/dirtyWhite"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/changeStatusBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/blood_orange"
fab:fab_size="normal"
app:fab_icon="@drawable/ic_textsms_white_48dp"
fab:fab_title="Change status"
fab:fab_colorPressed="@color/dirtyWhite"/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>
</android.support.design.widget.CoordinatorLayout>
这是我的片段,包含recyclerview布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/tab_bg">
<android.support.v7.widget.RecyclerView
android:id="@+id/feedCardViewList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="true"
xmlns:android="http://schemas.android.com/apk/res/android"/>
</RelativeLayout>
主要布局的内容:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".UI.MainActivity"
tools:showIn="@layout/activity_main"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</RelativeLayout>
尝试在您的viewpager标签中给出Android:MarginBottom=“5dp”
,这里您使用布局高度作为“匹配父项”,因此它覆盖了底部区域 我也有同样的问题,所以我暂时在android:layout_marginBottom=“55dp”上加了一个55dp的底边距,看起来不错,我希望这个问题能很快得到解决。可能的重复
您可以尝试将工具栏的
app:layout\u scrollFlags=“scroll | enterally”
属性更改为app:layout\u scrollFlags=“enterally”
今天遇到了这个问题。我不确定我是否不知何故遗漏了一些东西,并且错误地实现了协调器布局,或者这是一个bug。但是,如果有人仍然有这个问题,我通过编程的方式解决了它,根据应用程序栏的高度调整工具栏下方内容的边距。这是:
布局XML:
<android.support.design.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">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
...collapsing toolbar content...
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
...content beneath toolbar...
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
每个人
我也面临着同样的问题
这个问题可以很容易地解决,只需删除
app:layout_scrollFlags=“scroll | enterally”
从XML文件中的工具条形码
我也遇到了同样的问题,但在删除此项后不久
viewpager在屏幕内自动排列(未超出屏幕限制)
这是默认代码
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
将此更改为
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">
底部第二行。如果删除app:layout_scrollFlags=“scroll | enterally”@GeorgiKoemdzhiev-content\u main的内容是什么?因为您有一个
ViewPager
,在ViewPager
下有一个布局。@GeorgiKoemdzhiev-我想这是因为SupportLibrary,目前还没有正式的答案@GeorgiKoemdzhiev-我可以为你的(通过创建一个新问题)做这件事,但是,当你指定一个查看页面时,这意味着,你也需要通过创建一个新闻版面来添加你的片段,这是另一个问题,顺便说一句,你需要删除包括,无论如何,我认为这是因为协调人布局,我认为我们应该联系谷歌员工。这是最好的官方网站,可以做到这一点-这是SupportLibrary的默认配置或默认设计,所以OP不需要更改任何内容。我已经尝试过了,这是一个解决问题的方法,它破坏了我的布局。谢谢你分享你的答案!我还没有测试过它,但我会接受你的答案,因为这是迄今为止最详细的一个,它也可以帮助其他人。这一个为我解决了它。竖起大拇指^^完美修复。谢谢这是另一个问题
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">