【发布时间】:2019-04-29 02:47:49
【问题描述】:
我正在尝试使工具栏在此布局中始终可见,而不是仅在完全滚动时才出现。我在折叠工具栏中有一个图像,当完全滚动时需要隐藏它。
这就是我尝试过的......关于如何实现它的任何意见?
<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=".activities.Event_details">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/topLayout"
app:layout_anchorGravity="top"
android:layout_gravity="top" >
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/toolbar"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorWhite"
android:id="@+id/toolbarTitle"
android:layout_centerVertical="true"
android:layout_marginEnd="?android:attr/actionBarSize"
android:textStyle="bold"
android:textSize="@dimen/page_innerheader_titletxt"
android:text="@string/app_name"/>
<TextView
android:id="@+id/save_toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save"
android:textColor="@color/colorYellow"
android:layout_centerVertical="true"
android:textSize="@dimen/textsize16"
android:layout_toStartOf="@id/toolbarButton"
android:layout_marginEnd="15dp"/>
<Button
android:id="@+id/toolbarButton"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="@string/done"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:textColor="@color/colorPrimary"
android:background="@drawable/rect_yellow"
android:layout_marginEnd="10dp"
/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</RelativeLayout>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="6dp"
app:layout_anchor="@id/topLayout"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/party"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>
<!--
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/toolbar"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorWhite"
android:id="@+id/toolbarTitle"
android:layout_centerVertical="true"
android:layout_marginEnd="?android:attr/actionBarSize"
android:textStyle="bold"
android:textSize="@dimen/page_innerheader_titletxt"
android:text="@string/app_name"/>
<TextView
android:id="@+id/save_toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save"
android:textColor="@color/colorYellow"
android:layout_centerVertical="true"
android:textSize="@dimen/textsize16"
android:layout_toStartOf="@id/toolbarButton"
android:layout_marginEnd="15dp"/>
<Button
android:id="@+id/toolbarButton"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="@string/done"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:textColor="@color/colorPrimary"
android:background="@drawable/rect_yellow"
android:layout_marginEnd="10dp"
/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
-->
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main_eventdetails" />
</android.support.design.widget.CoordinatorLayout>
P.S:我也尝试使用折叠工具栏内的工具栏,但我只能使标题和按钮可见,但我希望整个工具栏有 colorPrimary 背景。
我尝试了这些链接 collapsing toolbar fixed 和这个 AppBar layout behaviour 以及一些来自其他 SO 线程的链接。但似乎没有什么能解决我的问题。
【问题讨论】:
-
可以添加截图吗?您需要什么或正在发生什么?
-
当你滚动时,通常在折叠工具栏与图像时,图像会折叠到工具栏(参考:medium.com/@tonia.tkachuk/…)。但我想要实现的是,工具栏在折叠之前应该始终是固定的,并且只有图像在滚动时才应该折叠。
标签: android android-coordinatorlayout android-collapsingtoolbarlayout