Android - 无法修复折叠工具栏布局中的工具栏

o_o

我目前在布局的上部使用 CollapsingToolbar 布局。我想折叠特定部分(仅限 LinearLayout)并将工具栏固定在顶部。我能够在另一个项目中将工具栏位置固定在顶部并防止其折叠。但是,由于某种原因,我无法固定工具栏的位置。任何帮助将不胜感激。这是我的布局的 XML:

<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
android:id="@+id/profile_coordinate_layout"
>

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|enterAlways"
        android:layout_gravity="fill_vertical"
        android:fitsSystemWindows="true"
        app:layout_collapseMode="pin"
        app:expandedTitleMarginStart="?actionBarSize"
        app:contentScrim="?colorPrimary"
        >

        <!--|||||||||||||||||||||||||||||||||||||||||||||||||-->
        <!--|||||||||||||||Collection Profile and about||||||-->
        <!--|||||||||||||||||||||||||||||||||||||||||||||||||-->
        <LinearLayout
            android:id="@+id/ll_header"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="?actionBarSize"
            android:orientation="vertical"
            app:layout_collapseMode="pin"
            android:background="@drawable/gradient_feed_bg"
            >
            <include
                layout="@layout/item_collection_profile" />
        </LinearLayout>


        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"
            android:background="@drawable/dark_primary_no_radius"
            app:layout_collapseMode="pin"
            android:elevation="@dimen/margin_4dp"
            >
            <include layout="@layout/action_bar_collection_profile"/>
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>


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

我正在 ViewPager 上加载另一个片段。我正在使用以下代码加载工具栏。

findViewById(R.id.toolbar). setBackgroundResource(R.drawable.dark_primary_no_radius);
setSupportActionBar((android.support.v7.widget.Toolbar)findViewById(R.id.toolbar));

这是更新的结果:

在此处输入图片说明

如您所见,在第二张图片中,工具栏折叠在顶部。任何帮助将不胜感激。

谢谢你。

达利什

您只需要app:layout_collapseMode="pin"在工具栏中使用。从 LinearLayout 和 CollapsingToolbarLayout 等其他组件中删除它。

<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.design.widget.CollapsingToolbarLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
  app:layout_scrollFlags="scroll|exitUntilCollapsed"
    android:layout_gravity="fill_vertical"
    android:fitsSystemWindows="true"
    app:expandedTitleMarginStart="?actionBarSize"
    app:contentScrim="?colorPrimary"
    >

    <!--|||||||||||||||||||||||||||||||||||||||||||||||||-->
    <!--|||||||||||||||Collection Profile and about||||||-->
    <!--|||||||||||||||||||||||||||||||||||||||||||||||||-->
    <LinearLayout
        android:id="@+id/ll_header"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?actionBarSize"
        android:orientation="vertical"
      app:layout_collapseMode="parallax"
        android:background="@drawable/gradient_feed_bg"
        >
        <include
            layout="@layout/item_collection_profile" />
    </LinearLayout>


    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        android:background="@drawable/dark_primary_no_radius"
        app:layout_collapseMode="pin"
        android:elevation="@dimen/margin_4dp"
        >
        <include layout="@layout/action_bar_collection_profile"/>
    </android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章