折叠工具栏.如何调整自定义布局而不是默认ImageView [英] Collapsing Toolbar. How to adapt custom Layout instead of default ImageView
问题描述
我要制作可折叠的工具栏,其中是我的自定义布局.下图显示了新发布的design.support lib的使用.在img.1上,元素(ImageView)消失了. 在我的项目中,我想消失一个版式. 由于Layout内部将是ViewPager,因此无法像图像一样调整大小,因此应该在工具栏背景中溶解-应该变得透明.
I want to make collasping toolbar, in which is my custom Layout . On the image below is presented use of new released design.support lib. On the img.1, the element (ImageView) is disappearing. In my project I want to disappear a Layout. Because inside Layout will be ViewPager it can not be resized like the image, it should dissolve in Toolbar background - should become transparent.
img. 1
此外,我想通过移动ToolbarFooter-要移动的皮带 -亮蓝色的布局打开/隐藏 ToolbarLayout.因此,展开/折叠与img.1中的不一样.相反,它应该类似于状态栏,通过在ToolbarFooter上单击来上下移动.
Additionaly I want to open/hide ToolbarLayout by moving ToolbarFooter - belt to move - bright blue Layout. So expand/collapse are not like in img.1 Instead it should works like status bar that shifts up and down by blick on ToolbarFooter.
img.2
我想我已经读了很多(与按钮合拢,内部布局),但我发现了任何线索或实现.我不知道该如何处理这个话题. 我想我的ViewPager和RelativeLayout(或其他)应该在工具栏之外.他们应该像这样代替工具栏视图:
The think is I read about it a lot (collapsing with button , layout inside) of but I've found any clue or implementation. I don't know how to approach to this topic. I suppose that my ViewPager and RelativeLayout(or whatever) should be outside of the toolbar. And they should just take a place of toolbar view like this:
<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重叠视图.伙计们,您向我推荐什么,我应该从哪一侧吃这块蛋糕?
Now can anyone tell me what component should I use? Support library offers CoordinateLayout, CollapsedToolbar, Appbar. By standard approach can be use RelativeLayout or FrameLayout which overlap view. So guys what you recommend me, how from which side should I eat this cake?
已更新:
最后,我找到了解决方案.它不是CollapsingToolbar,而是ViewDragHelper. 我遵循的解决方案:博客, GitHub项目,
Finally I've found the solution. It isn't CollapsingToolbar but ViewDragHelper. The solution I followed: Blog, GitHub project, YouTube explanation,
推荐答案
您需要在工具栏上方附加一个viewPager. ImageView的示例:
You need attach a viewPager above toolbar. Example for 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>
这篇关于折叠工具栏.如何调整自定义布局而不是默认ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!