折叠式工具栏。如何适应自定义布局而不是默认的ImageView?

4

我想制作一个可折叠的工具栏,其中包含我的自定义布局。下面的图片展示了新发布的design.support库的使用。在img.1中,元素(ImageView)消失了。在我的项目中,我想让一个布局消失。 因为ViewPager在里面,它不能像图片那样被调整大小,它应该溶解在Toolbar背景中 - 应该变成透明的。

enter image description here img. 1

此外,我希望通过移动ToolbarFooter - 移动的带子 - 明亮蓝色的布局来打开/隐藏ToolbarLayout。所以展开/折叠不像img.1那样,相反它应该像状态栏一样工作,通过点击ToolbarFooter上的闪烁而向上和向下移动。

enter image description here img.2

问题是我读了很多关于它的文章(带按钮折叠内部布局),但我没有找到任何线索或实现。我不知道如何处理这个问题。 我想我的ViewPager和RelativeLayout(或其他)应该在工具栏之外。它们只需要占据工具栏视图的位置,就像这样:

<android.support.v4.widget.DrawerLayout
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">

<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:clipChildren="false">

    <android.support.v7.widget.Toolbar
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_max_height"
        android:minHeight="?attr/actionBarSize"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:theme="@style/AppBarTheme">

        <Button
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_alignParentTop="true"
            android:layout_gravity="left|top"
            android:gravity="center_vertical|left"
            android:text="ToolbarTitle"                
            android:background="?android:attr/selectableItemBackground"
            android:textAllCaps="false"/>
    </android.support.v7.widget.Toolbar>


    <net.android.app.views.ViewPagerToolbar
        android:id="@+id/calendar_viewpager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="?attr/actionBarSize"/>


    <RelativeLayout
        android:id="@+id/toolbar_footer"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:layout_alignParentTop="false"
        android:layout_alignBottom="@+id/app_bar">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="8dp"
                android:text="@string/belt_to_move"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:text="@string/belt_to_move"/>
    </RelativeLayout>

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/app_bar">

        <android.support.v4.view.ViewPager
            android:id="@+id/vp_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </android.support.v4.widget.DrawerLayout>
</RelativeLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/navView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"/>

现在有人能告诉我应该使用哪个组件吗?支持库提供了CoordinateLayout、CollapsedToolbar和Appbar。按照标准方法,可以使用RelativeLayout或FrameLayout来重叠视图。那么,你们建议我用什么方法来解决这个问题呢?

更新:

最终我找到了解决方案。不是CollapsingToolbar,而是ViewDragHelper。我遵循的解决方案:博客GitHub项目YouTube解释


你有查看过 cheesesquare 应用程序吗?你具体有什么问题?是遇到了问题,还是只是一个明目张胆的代码请求? - tachyonflux
谢谢您的回答,我稍微改变了问题的背景以使其更清晰。这并不是完整的答案。在Cheesesquare项目中,ImageView消失了,我想使用我的自定义布局,但当我将其放在ImageView的位置时它无法工作。 - murt
请附上完整的layout.xml文件内容。 - Sergey Shustikov
1个回答

1
你需要在工具栏上方添加一个 viewPager。 例如 ImageView:
<android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="240dp"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:elevation="2dp">

<android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:elevation="2dp"
            app:collapsedTitleTextAppearance="?attr/autoCompleteTextViewStyle"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

 <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                >

             // put here your content

                <android.support.v7.widget.Toolbar
                        android:id="@+id/anim_toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        app:layout_collapseMode="pin"
                        app:elevation="2dp"
                        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
 </RelativeLayout>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

也许它能完成工作,但是你忘记了要使用 ToolbarFooter 来展开/折叠工具栏。 - murt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接