Android 如何在折叠工具栏布局中固定RelativeLayout
我正在为我的活动使用CollasingToolbar布局。是否有一种方法可以固定包含工具栏的RelativeLayout,而不是固定工具栏?我试着做了以下工作,但当布局崩溃时,RelativeLayout并没有固定在顶部Android 如何在折叠工具栏布局中固定RelativeLayout,android,android-layout,Android,Android Layout,我正在为我的活动使用CollasingToolbar布局。是否有一种方法可以固定包含工具栏的RelativeLayout,而不是固定工具栏?我试着做了以下工作,但当布局崩溃时,RelativeLayout并没有固定在顶部 <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/
<?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">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="@color/pale_red"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="230dp"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax">
<android.support.v4.view.ViewPager
android:id="@+id/carViewPager"
android:layout_width="match_parent"
android:layout_height="230dp"/>
<LinearLayout
android:id="@+id/image_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_gravity="bottom|center"
android:background="@android:color/transparent" />
</FrameLayout>
<RelativeLayout
android:id="@+id/toolbarLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<TextView
android:id="@+id/activityTitle"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_gravity="center"
android:gravity="center"
android:textSize="16sp"
android:text="@string/shop_info"
android:textColor="@color/white" />
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_shop" />
</android.support.design.widget.CoordinatorLayout>
就像它的名字正在折叠一样,工具栏之外的所有东西在向上滚动时都将被折叠,锁定它的唯一方法是在工具栏上使用“锁定”,只有工具栏可以使用“锁定”。 因此,请尝试将您的RelativeLayout放在折叠工具栏布局的外部,但放在AppBarLayout的内部,也许这正是您所需要的 我通过这个问题解决了它: 只需将您的布局视为此问题中提到的表格布局
希望能有所帮助。删除RelativeLayout并将TextView放在工具栏中如何刚刚尝试过,但默认情况下TextView没有消失。我希望TextView仅在布局折叠时显示。