如何防止布局在协调器布局内随工具栏一起移动?
How to prevent a layout moving along with toolbar inside a coordinator layout?
我有一个 HomeActivity,它有包含片段的选项卡。其中 BoardFragment 有子 RecyclerView 和一个 RelativeLayout(在底部)。当我向上滚动时,我的工具栏会折叠。但是我在底部的 RealtiveLayout 也与它们协调。只有它的上半部分显示在 oncreate 上。当我向上滚动时它完全显示出来。
这是截图。
主页活动。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
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:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_menu_white_24dp"
/>
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="150dp"
app:popupTheme="@style/AppTheme.PopupOverlay"
/>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_input_add"
android:visibility="invisible" />
棋盘碎片。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="io.sleeko.fragment.BoardFragment"
android:background="#dadada">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/boardMainContentList"
>
</android.support.v7.widget.RecyclerView>
<com.github.rahatarmanahmed.cpv.CircularProgressView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/spinningProgressView"
android:layout_width="36dp"
android:layout_height="36dp"
android:padding="4dp"
android:background="@drawable/white_circle_drawable"
android:layout_centerHorizontal="true"
android:layout_marginTop="150dp"
app:cpv_thickness="3dp"
app:cpv_color="#ff161a73"
app:cpv_animAutostart="true"
app:cpv_indeterminate="true"
android:elevation="4dp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="96dp"
android:layout_alignParentBottom="true"
android:duplicateParentState="true"
android:background="#ffffff"
android:padding="8dp"
android:id="@+id/sendMessageContainer"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Write a Message"
android:padding="8dp"
android:background="@android:color/transparent"
/>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:fabSize="mini"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:id="@+id/sendButton"
android:src="@drawable/ic_send_white_24dp"
/>
</RelativeLayout>
</RelativeLayout>
谁能帮我解决这个问题?
谢谢。
我以前遇到过类似的问题。你不需要 app:layout_behavior="@string/appbar_scrolling_view_behavior"
inside viewpager inside HomeActivity layout。我想这会解决你的问题。
我有一个 HomeActivity,它有包含片段的选项卡。其中 BoardFragment 有子 RecyclerView 和一个 RelativeLayout(在底部)。当我向上滚动时,我的工具栏会折叠。但是我在底部的 RealtiveLayout 也与它们协调。只有它的上半部分显示在 oncreate 上。当我向上滚动时它完全显示出来。
这是截图。
主页活动。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
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:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_menu_white_24dp"
/>
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="150dp"
app:popupTheme="@style/AppTheme.PopupOverlay"
/>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_input_add"
android:visibility="invisible" />
棋盘碎片。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="io.sleeko.fragment.BoardFragment"
android:background="#dadada">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/boardMainContentList"
>
</android.support.v7.widget.RecyclerView>
<com.github.rahatarmanahmed.cpv.CircularProgressView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/spinningProgressView"
android:layout_width="36dp"
android:layout_height="36dp"
android:padding="4dp"
android:background="@drawable/white_circle_drawable"
android:layout_centerHorizontal="true"
android:layout_marginTop="150dp"
app:cpv_thickness="3dp"
app:cpv_color="#ff161a73"
app:cpv_animAutostart="true"
app:cpv_indeterminate="true"
android:elevation="4dp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="96dp"
android:layout_alignParentBottom="true"
android:duplicateParentState="true"
android:background="#ffffff"
android:padding="8dp"
android:id="@+id/sendMessageContainer"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Write a Message"
android:padding="8dp"
android:background="@android:color/transparent"
/>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:fabSize="mini"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:id="@+id/sendButton"
android:src="@drawable/ic_send_white_24dp"
/>
</RelativeLayout>
</RelativeLayout>
谁能帮我解决这个问题? 谢谢。
我以前遇到过类似的问题。你不需要 app:layout_behavior="@string/appbar_scrolling_view_behavior"
inside viewpager inside HomeActivity layout。我想这会解决你的问题。