【问题标题】:Collapsing Toolbar. How to adapt custom Layout instead of default ImageView折叠工具栏。如何适应自定义布局而不是默认的 ImageView
【发布时间】:2015-08-19 17:23:57
【问题描述】:

我想制作折叠工具栏,其中是我的自定义布局。下图展示了新发布的 design.support 库的使用。在 img.1 上,元素 (ImageView) 正在消失。 在我的项目中,我想消失一个布局。 因为 Layout 内部将是 ViewPager,所以它不能像图像一样调整大小,它应该溶解在 Toolbar 背景中 - 应该变得透明。

img。 1

另外我想打开/隐藏 ToolbarLayout,通过移动 ToolbarFooter - 带移动 - 亮蓝色布局。因此展开/折叠不像在 img.1 中那样,而是应该像状态栏一样工作,通过在 ToolbarFooter 上的 blick 上下移动。

img.2

我的想法是我读了很多(collapsing with button,layout inside),但我发现了任何线索或实现。我不知道如何处理这个话题。 我想我的 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。 我遵循的解决方案:Blog,GitHub project,YouTube explanation,

【问题讨论】:

  • 您检查过cheesesquare 应用程序吗?你的问题到底是什么?你遇到问题了吗?或者这只是一个公然的代码请求?
  • 感谢您的回答,我稍微更改了问题的上下文以使其更清楚。这不是这个问题的完整答案。在 Cheesesquare 项目中,ImageView 消失了,我想使用我的自定义布局,当我放置它而不是 ImageView 时它将不起作用
  • 请附上完整的layout.xml文件内容。

标签: android android-animation fadeout android-collapsingtoolbarlayout


【解决方案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 将用于展开/折叠工具栏
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多