我想隐藏我的AppBarLayout以动态添加视图,这将占用屏幕的高度.为此,我想通过将AppBarLayout的可见性设置为GONE来临时删除视图.视图不可见,但占据屏幕空间(屏幕高度的一半).
我的XML代码:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorFriendProfil"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#81D4FA"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/fProfilAppBar"
android:layout_width="match_parent"
android:layout_height="250dp"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/fProfilCollapsing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#B3E5FC"
android:gravity="center"
android:orientation="vertical"
app:contentScrim="#03A9F4"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:id="@+id/fProfilUserInfo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<com.neden.neden.RoundedImageView
android:id="@+id/ivFriendPicture"
android:layout_width="150sp"
android:layout_height="150sp"
android:layout_gravity="center"
android:fitsSystemWindows="true"
android:src="@drawable/photo"
app:border_color="#64B5F6"
app:border_width="4dp"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7" />
<TextView
android:id="@+id/fProfilName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="15pt" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/fProfilToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/fProfilContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
Run Code Online (Sandbox Code Playgroud)
我想添加图像来显示问题,但我不能因为我的声誉.对不起英语很糟糕,我的发言不太好.
android android-coordinatorlayout android-collapsingtoolbarlayout android-appbarlayout
我的应用程序主屏幕包含图像的网格视图.当用户选择图像时,使用共享元素转换开始细节活动,该共享元素转换将所选择的网格图像动画化为位于细节活动中的CardView中的配对图像.
升级我的详细视图XML布局以包含CoordinatorLayout以及CollapsingToolbarLayout后,共享元素转换将图像视图移动到详细活动中的错误位置("enter"活动).如果在包含目标图像视图的CardView上方没有CollapsingToolBarLayout,框架似乎会将整个AppBarLayout和内部CollapsingToobarLayout的偏移量和动画放大到图像的大致位置.
通过将activityView(带有transitionName)添加到activity_detail.xml中的3个CardView中的任何一个,可以在Chris Banes的cheesesquare示例应用程序中复制该问题:
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:transitionName="sharedImage" />
Run Code Online (Sandbox Code Playgroud)
然后在CheeseListFragment.java中的onBindViewHolder中设置共享元素转换,如下所示:
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
holder.mBoundString = mValues.get(position);
holder.mTextView.setText(mValues.get(position));
holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Context context = v.getContext();
Intent intent = new Intent(context, CheeseDetailActivity.class);
intent.putExtra(CheeseDetailActivity.EXTRA_NAME, holder.mBoundString);
holder.mImageView.setTransitionName("sharedImage");
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(
getActivity(v.getContext()),
holder.mImageView,
"sharedImage");
ActivityCompat.StartActivity((MyActivity) context, intent, options.toBundle());
}
});
Glide.with(holder.mImageView.getContext())
.load(Cheeses.getRandomCheeseDrawable())
.fitCenter()
.into(holder.mImageView);
}
Run Code Online (Sandbox Code Playgroud)
如果运行应用程序,并单击奶酪列表项,您将了解过渡动画如何将图像移动到目标活动视图中的错误(太高)偏移.动画完成后,图像将"扭曲"到正确的位置.
任何关于可能的解决方法的想法都会非常受欢迎.
animation android shared-element-transition android-coordinatorlayout android-collapsingtoolbarlayout
我遇到了很多与我的问题有关的问题,但我发现没有人想要我正在寻找的行为.
我想要一个带有标签和应用栏的视图寻呼机,当所包含的片段可滚动并滚动(朝向底部)时,我希望应用栏消失,但是当向上滚动时,将标签留下以重新显示.其中一些片段包含SwipeToRefresh布局(有时会导致问题).我尝试了很多配置,总是会出错.
现在我没有崩溃效果(它总是隐藏)
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainPagerActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<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:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|enterAlways">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabIndicatorHeight="6dp"
app:tabMode="fixed" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/main_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/app_bar_layout"
tools:context=".MainPagerActivity"
/>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_menu_edit" />
Run Code Online (Sandbox Code Playgroud)
和我的一个片段(滚动的一个):
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:wheel="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.m360learning.app.fragment.MainPagerNewsFeed">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout …Run Code Online (Sandbox Code Playgroud) android swiperefreshlayout android-toolbar android-coordinatorlayout android-collapsingtoolbarlayout
我有一个CollapsingToolbarLayout被定义为在折叠和扩展模式中居中:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="286dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:collapsedTitleGravity="center"
app:expandedTitleGravity="center"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/backgroundImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@null"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll|exitUntilCollapsed"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|exitUntilCollapsed"/>
<ImageView
android:id="@+id/someIcon"
android:layout_width="56dp"
android:layout_height="wrap_content"
android:src="@drawable/some_icon"
android:padding="16dp"
android:layout_gravity="top|end"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
我为工具栏定义了一个标题,但当我折叠它时,我可以看到标题在对角线方向上移动而不是直线向上,并且它略微与工具栏中心的右侧对齐.请注意,宽度是match_parent,折叠的重力是中心,所以为什么会发生这种情况,我该如何解决?
• 第一个截图:如果我使用折叠 - >中心和展开 - >中心重力然后折叠布局,它看起来是什么样的.请注意,它位于屏幕中心的右侧.
• 第二个截图:如果我摆脱崩溃的样子 - >中心引力但是保持扩展 - >中心引力然后折叠布局.请注意,它默认为左对齐.
• 第三个屏幕截图:它看起来像是扩展的
到目前为止我已经尝试过解决这个问题的事情(没有成功):
•摆脱collapsedGravity并只留下expandFravity
•使用标题的默认roboto字体
•为工具栏和折叠布局设置填充和边距为0
•设置gravity center_horizontal而不是center
我发现这个工作正常的唯一解决方法是使用单独的textview来保存标题,而不是设置collapsingtoolbarlayout的标题(这使标题正确地折叠到中心).这不是最佳的,所以我很高兴知道CPL中是否有错误,或者是否有办法使用默认标题来做同样的事情.
所以,我CollapsingToolbarLayout在项目中遇到了一个奇怪的问题.我的活动开始后,这是我的工具栏标题出现的方式:
折叠后布局如下:
示例中的原始标题文本是:" UPC VONALKODOS TERMEK "
我认为扩展状态下的标题应该比崩溃状态更长(有足够的空间).这就是我的活动的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="match_parent"
android:fitsSystemWindows="true"
app:theme="@style/PolarThemeNoActionBar">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_below="@+id/tablayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="142dp"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginBottom="20dp"
app:expandedTitleTextAppearance="@style/ExpandedText">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.TabLayout
android:id="@+id/tablayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_below="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:gravity="bottom"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabIndicatorColor="?attr/colorPrimaryDark"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
我的res/style/ExpandedText看起来像:
<style name="ExpandedText" parent="android:TextAppearance">
<item name="android:textColor">@android:color/white</item>
<item name="android:textSize">20sp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
支持库版本:25.1.1. 电话:Nexus 5 Android版本:6.0.1(股票)
我的问题:为什么标题在扩展状态下最后有点,而没有填充空间以显示更多内容?
[编辑1] …
android android-design-library android-collapsingtoolbarlayout
我有以下设计,其中顶部和下方有一个CollapsingToolbarLayout,有一个RelativeLayout:
我希望RelativeLayout填充剩下的空间直到底部,所以我可以像这样集中内容:
我尝试在RelativeLayout上使用match_parent但它需要整个根布局的大小,包括CollapsingToolbarLayout:
我能做什么?这是完整布局的代码:
<?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"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".UserActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorWhite">
<android.support.design.widget.AppBarLayout android:id="@+id/activity_user_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout android:id="@+id/activity_user_collapsingtoolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar android:id="@+id/activity_user_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_collapseMode="pin">
<!-- toolbar content -->
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout android:id="@+id/activity_user_eventsalert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/calendar_remove_titlegray_48px"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="No events yet"
android:textSize="20sp"
android:textColor="@color/colorTitleGray"/>
</LinearLayout>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_gravity="bottom"
android:background="@drawable/shadow_bottom_white_to_transparent"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) android android-layout android-relativelayout android-collapsingtoolbarlayout
我正在尝试使用NestedScrollView实现CollapsingToolbarLayout,它在底部的NestedScrollView中显示TextView,不允许,滚动或折叠工具栏.我已经使用了RecyclerView而不是NestedScrollView.当我删除app:layout_behavior="@string/appbar_scrolling_view_behavior工具栏折叠但NestedScrollView不在AppBarLayout之下时.有任何解决方案或建议来解决这个问
XML
<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="match_parent"
android:fitsSystemWindows="true">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Hello"
android:textColor="#000"
android:textSize="16sp"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="134dp"
android:background="@color/primary"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
结果

android android-design-library androiddesignsupport android-collapsingtoolbarlayout
我正在使用Android设计支持库创建一个带有可折叠工具栏的活动,其效果很好,就像Google Play或Whatsapp的联系人个人资料一样.我将活动布局放在最后但请记住,这只是默认的可折叠活动布局,我将ImageView添加到AppBarLayout以创建工具栏< - >图像淡入淡出效果.
我对这个实现的问题表现为我将描述的两个症状:
活动内容很长,当我想快速向上滚动时,滚动将在展开工具栏之前停止.我希望它继续,当我在我的NestedScrollView的底部,我做一个快速的手指滑动,一直到我的活动的顶部我希望这个滚动去扩展工具栏,这是方式谷歌Play应用程序表现或Whatsapp的个人资料.
类似地,当工具栏展开时,滚动没有惯性,快速向下滑动会滚动一点点,这也不是Google Play或Whatsapp配置文件的行为方式.折叠工具栏后,滚动的行为与ScrollViews,ListViews等中的滚动一样.快速滑动将允许您进入底部或顶部(除非有大量内容).
我描述的行为是否由设计支持库支持?
activity.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".ScrollingActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:fitsSystemWindows="true"
android:layout_height="@dimen/app_bar_height_custom"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary">
<ImageView
android:src="@drawable/cuthbert"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
android:minHeight="100dp"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_scrolling"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"
android:src="@android:drawable/ic_dialog_email"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
content_scrolling.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_scrolling"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ScrollingActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin" …Run Code Online (Sandbox Code Playgroud) android android-collapsingtoolbarlayout android-appbarlayout
我想在"折叠"工具栏中显示一些文本而不是标题.问题是文本可能包含多于1行.所以我需要使用自定义视图,但无法理解如何以适当的方式实现它.
另外,如何设置最小CollapsingToolbar高度,始终显示所有文本行,而不是将它们折叠为一个?
总之,我需要这样的东西:
1 - 开始位置和3 - 结束位置(达到此工具栏高度后不再崩溃).
android android-layout material-design android-collapsingtoolbarlayout
CollapsingToolbarLayout只有有工作RecyclerView但不与工作ListView和GridView.
下面是我的XML文件:
<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="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="192dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<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:expandedTitleMarginBottom="32dp"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/restaurant_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/gradiant"
app:layout_collapseMode="parallax" />
<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:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fillViewport="true">
<GridView
android:id="@+id/restaurant_items"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:gravity="center"
android:numColumns="2"
android:verticalSpacing="20dp" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
这个是我的Activity档案:
Toolbar toolbar = (Toolbar) findViewById(R.id.anim_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
CollapsingToolbarLayout collapsingToolbar = …Run Code Online (Sandbox Code Playgroud)