Java 显示在折叠工具栏顶部的视图
编辑:问题解决了。见布莱克贝尔的评论 我一直在尝试在我的项目中实现折叠工具栏,坚持使用Google提供的一个示例。我已经让它大部分工作,但视图显示在工具栏的顶部而不是下方 下面,我粘贴了承载工具栏的活动的XML代码Java 显示在折叠工具栏顶部的视图,java,android,xml,material-design,Java,Android,Xml,Material Design,编辑:问题解决了。见布莱克贝尔的评论 我一直在尝试在我的项目中实现折叠工具栏,坚持使用Google提供的一个示例。我已经让它大部分工作,但视图显示在工具栏的顶部而不是下方 下面,我粘贴了承载工具栏的活动的XML代码 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.andro
<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="android.jochemkleine.com.popularmovies.ui.MovieDetailActivity"
android:background="#57ffffff">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
android:id="@+id/toolbarImage"
/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/item_detail_container">
</FrameLayout>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/btn_star_big_off"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"
android:scaleType="center"
app:backgroundTint="#ffffff"/>
请注意,id为item_detail_容器的FrameLayout将包含一个片段。
所述片段用于以下XML文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_movie_details"
tools:context="android.jochemkleine.com.popularmovies.ui.m"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST TEXTVIEW"
/>
</LinearLayout>
请注意,现在这个XML文件中的LinearLayout没有任何用途,因为只存在一个TextView。不过,它将在以后使用,因为NestedScrollView只能承载一个直接子级
我相当肯定错误在第一个XML文件中的某个地方,可能是由于使用了FrameLayout。让我感到困惑的是,谷歌的例子几乎完全一样,唯一的区别是它们包含了一个布局,而不是使用框架布局
提前感谢;非常感谢您的帮助。是否将嵌套的滚动视图充气到框架布局中?你把
app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”
添加到FrameLayout中会发生什么?我简直不敢相信,但这就成功了。我至少花了一两个小时试图把它做好。谢谢!