android - 折叠工具栏。如何调整自定义布局而不是默认的 ImageView

标签 android android-animation fadeout android-collapsingtoolbarlayout

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

enter image description here图像。 1

此外,我想通过移动 ToolbarFooter - 带移动 - 亮蓝色布局来打开/隐藏 ToolbarLayout。所以展开/折叠不像 img.1 中那样,它应该像状态栏一样工作,通过点击 ToolbarFooter 上下移动。

enter image description here img.2

我的想法是我读了很多( collapsing with buttonlayout inside )但是我找到了任何线索或实现。我不知道如何处理这个话题。 我想我的 ViewPager 和 RelativeLayout(或其他)应该在工具栏之外。它们应该像这样取代工具栏 View :

<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。 通过标准方法可以使用重叠 View 的 RelativeLayout 或 FrameLayout。那么大家有什么建议吗,我应该从哪一边吃这个蛋糕?

更新:

我终于找到了解决方案。它不是 CollapsingToolbar,而是 ViewDragHelper。 我遵循的解决方案:Blog , GitHub project , YouTube explanation ,

最佳答案

您需要在工具栏上方附加一个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>

关于android - 折叠工具栏。如何调整自定义布局而不是默认的 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32101891/

相关文章:

android - onInputShowListener Android - 是否可以检测是否显示任何软键盘?

android - 通过触摸或手势识别移动 RecyclerView

Android alpha动画淡入淡出延迟

css - 交叉淡入淡出图像库,剩下 3 张图像

android - 通过android信任一个证书

android - 如何在 Android 设备上禁用 "Re-start: Cold restart"物理按钮

android - decodeIndirectRef 中的间接引用 0x416f68a0 无效

android - 在使用 bringToFront() 方法时遇到问题

android - 使用动画来滑动 View

JQuery:淡出所有其他 div 并将 $(this) 移到左上角