如何在不滚动android的情况下将正在折叠的工具栏显示为已折叠
我有一个折叠的工具栏布局。我已经在上面显示了图表。因此,如果图形中没有要显示的项目,我希望将正在折叠的工具栏布局显示为折叠、隐藏或关闭。只显示工具栏和标题,而不显示图形 以下是视图: 我只想显示左侧有菜单图标的工具栏 布局代码:如何在不滚动android的情况下将正在折叠的工具栏显示为已折叠,android,layout,android-collapsingtoolbarlayout,Android,Layout,Android Collapsingtoolbarlayout,我有一个折叠的工具栏布局。我已经在上面显示了图表。因此,如果图形中没有要显示的项目,我希望将正在折叠的工具栏布局显示为折叠、隐藏或关闭。只显示工具栏和标题,而不显示图形 以下是视图: 我只想显示左侧有菜单图标的工具栏 布局代码: <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://s
<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:layout_gravity="center"
tools:context="com.example.siddhi.googletaskmanager"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true"
android:id="@+id/parentPanel"
android:background="@color/background">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="220dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:id="@+id/appbar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:titleEnabled="false"
app:contentScrim="?attr/colorPrimary"
android:fitsSystemWindows="true"
app:expandedTitleTextAppearance="@style/expandedappbar"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<com.github.mikephil.charting.charts.HorizontalBarChart
android:id="@+id/chart"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="@+id/toolbar"
app:layout_collapseMode="parallax"
android:layout_gravity="bottom"
android:layout_marginBottom="40dp"/>
<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.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:paddingTop="10dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<com.github.clans.fab.FloatingActionMenu
android:id="@+id/menu1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
app:menu_colorNormal="@color/colorAccent"
app:menu_colorPressed="@color/colorAccent"
fab:menu_icon="@drawable/ic_more_horiz_white_24dp"
fab:menu_labels_ellipsize="end"
fab:menu_labels_singleLine="true"
fab:menu_backgroundColor="@color/colorPrimary"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_list_white_24dp"
fab:fab_size="mini"
fab:fab_label="List 1"
app:fab_colorPressed="@color/colorAccent"
app:fab_colorNormal="@color/colorAccent"/>
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_list_white_24dp"
fab:fab_size="mini"
fab:fab_label="List 2"
app:fab_colorPressed="@color/colorAccent"
app:fab_colorNormal="@color/colorAccent"/>
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_list_white_24dp"
fab:fab_size="mini"
fab:fab_label="List 3"
app:fab_colorPressed="@color/colorAccent"
app:fab_colorNormal="@color/colorAccent"/>
</com.github.clans.fab.FloatingActionMenu>
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_white_24dp"
fab:fab_size="normal"
app:fab_colorPressed="@color/colorAccent"
app:fab_colorNormal="@color/colorAccent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="80dp"
android:layout_marginEnd="80dp"
android:layout_marginBottom="10dp" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
尺寸:
<dimen name="toolbar_height">128dp</dimen>
<dimen name="appbar_height">200dp</dimen>
128dp
200dp
我怎样才能做到这一点?
谢谢。您可以使用
appBarLayout.setExpanded(真/假)
以编程方式完成此操作
核心问题是没有折叠ToolbarLayout.lock();迄今为止的方法(支架设计第23.2.1版)
是一个真正有效的完整解决方案很好这很有效。。但是,我以后可以扩展它。我应该无法展开appbar。如何做到这一点@David Seroussii如果我将scroll flag设置为0,则图形也会显示,我无法折叠工具栏@David Seroussied再次编辑,链接到另一个答案您能告诉我默认工具栏高度是多少吗?我尝试使用这个解决方案。但是,如果我将工具栏高度设置为89 dp,它在800x1280大小的设备上看起来非常完美,但在更小的设备上,应用程序栏可以滚动@David SeroussiI不确定,但我认为最近的高度是
56dp
<dimen name="toolbar_height">128dp</dimen>
<dimen name="appbar_height">200dp</dimen>
if(yourGraphIsEmpty){
appBarLayout.setExpanded(false);
}else{
appBarLayout.setExpanded(true);
}