在android中,如何在滚动时修复工具栏?
在发布这个问题之前,我已经研究了之前的所有问题,之前的任何解决方案都不适合我。我需要使我的工具栏在滚动时是静态的,滚动时它会向上移动,但我需要使它是静态的,我如何才能做到这一点。现在让我解释一下我到目前为止尝试过的所有方法 我已进入WindowsOfInputMode以调整大小 窗户 布局正确 这是我写的代码: 这是主要的协调布局: 这是布局文件:在android中,如何在滚动时修复工具栏?,android,material-design,toolbar,android-scroll,Android,Material Design,Toolbar,Android Scroll,在发布这个问题之前,我已经研究了之前的所有问题,之前的任何解决方案都不适合我。我需要使我的工具栏在滚动时是静态的,滚动时它会向上移动,但我需要使它是静态的,我如何才能做到这一点。现在让我解释一下我到目前为止尝试过的所有方法 我已进入WindowsOfInputMode以调整大小 窗户 布局正确 这是我写的代码: 这是主要的协调布局: 这是布局文件: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:andr
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_incident"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/incident_recyclerview"
android:divider="#fff"
android:keepScreenOn="true"
android:dividerHeight="0.5dp"
/>
</RelativeLayout>
我只是想让我的工具栏静态我如何才能实现感谢提前 删除应用程序:layout\u scrollFlags=scroll |始终从工具栏中输入此项并选中scroll。删除应用程序:layout\u scrollFlags=scroll |始终从工具栏中输入此项并选中scroll。使您的布局像这样。滚动布局时,工具栏将固定在顶部
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlwaysCollapsed"
app:statusBarScrim="@color/primary"
app:contentScrim="@color/primary"
app:titleEnabled="false"
app:layout_collapseMode="none"
android:fitsSystemWindows="true">
<!--
we must create the value entry for the toolbar height here as different version would have different heights
-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:gravity="top"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
让你的布局像这样。滚动布局时,工具栏将固定在顶部
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlwaysCollapsed"
app:statusBarScrim="@color/primary"
app:contentScrim="@color/primary"
app:titleEnabled="false"
app:layout_collapseMode="none"
android:fitsSystemWindows="true">
<!--
we must create the value entry for the toolbar height here as different version would have different heights
-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:gravity="top"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
好吧有很多答案但是 这就是你要找的吗? 如果是,您可以使用 对于第二个视图,这里是我的xml,您只需删除ImageView即可获得第一个视图
<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:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/profile_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/monkey"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffe5e5e5"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/activity_second" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
请注意,我已经为工具栏使用了app:layout\u collapseMode=pin
玩得开心^ ^好的,有很多答案,但是 这就是你要找的吗? 如果是,您可以使用 对于第二个视图,这里是我的xml,您只需删除ImageView即可获得第一个视图
<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:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/profile_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/monkey"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffe5e5e5"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/activity_second" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
请注意,我已经为工具栏使用了app:layout\u collapseMode=pin
玩得开心^ ^可能重复@M.Yogeshwaran您想让工具栏保持在相同的位置,或者这意味着什么?再次需要使我的工具栏在滚动时保持静态滚动时它会在滚动时上升,但我需要使其保持静态与布局无关我不会与协调员一起工作layout@Charuක 您好,我不希望工具栏移动它需要静态添加嵌套的ScrollView在AppBarLayout之后它会工作。可能重复@M.Yogeshwaran您想保持工具栏在相同的位置,或者这意味着什么?再次需要使我的工具栏在滚动时保持静态滚动时它会在滚动时上升,但我需要使其保持静态无需做任何事情对于布局,我将不与协调员一起工作layout@Charuක 您好,我不希望工具栏移动它需要静态添加嵌套滚动视图AppBarLayout之后它会工作。@M.Yogeshwaran您检查过这个吗answer@M.Yogeshwaran你核对过这个答案了吗