gpt4 book ai didi

java - Android - 如何将工具栏固定在 AppBar 的顶部

转载 作者:行者123 更新时间:2023-11-30 10:27:18 26 4
gpt4 key购买 nike

我试图在滚动浏览内容时修复工具栏。当前,滚动时工具栏会消失。我试过这个solution但我没能成功。到目前为止,我还没有解决方法。任何帮助将不胜感激。这是我的 XML 布局和相关布局的图片。

    <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator"
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.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="220dp"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

<android.support.v4.view.ViewPager
android:id="@+id/pager_most_read"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="220dp"
android:layout_alignParentTop="true"
android:background="@android:color/transparent">
</android.support.v4.view.ViewPager>

<android.support.v7.widget.Toolbar
android:layout_alignParentTop="true"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#0000ff"
app:layout_collapseMode="pin">
</android.support.v7.widget.Toolbar>

<me.relex.circleindicator.CircleIndicator
android:layout_alignParentBottom="true"
android:id="@+id/indicator"
android:layout_width="match_parent"
android:layout_height="48dp" />

</RelativeLayout>

<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:tabIndicatorColor="@color/text_selected"
app:tabMode="scrollable"
app:tabSelectedTextColor="@color/text_selected"
app:tabTextColor="@color/gray"/>

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


<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>

<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>

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

enter image description here

最佳答案

已经有一段时间了,但我设法解决了它,所以这是代码:

    <android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"
app:title="Title" />

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Title">

<!-- Action bar content -->

</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"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<!-- scrollable content -->

</android.support.v4.widget.NestedScrollView>


<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
... />

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

关于java - Android - 如何将工具栏固定在 AppBar 的顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45352473/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com