我正在努力CollapsingToolbarLayout.我不知道在工具栏中固定标题的方法.
有没有简单的方法来实现这一目标?
我有一个CollapsingToolbarLayout包含a TextView和a RatingBar的TextView.是否有可能以TextView某种方式过渡到标题?
我希望"标题"在工具栏折叠时转换.还会有一个后退按钮,那么我如何确保textview转换到正确的位置(后退按钮的右侧)?
编辑:这是我的XML
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
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:layout_width="match_parent"
android:layout_height="@dimen/detail_view_app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleTextAppearance="@style/CollapsingToolbarLayoutExpandedTextStyle"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="@dimen/double_margin"
android:gravity="center_vertical"
android:orientation="vertical"
app:layout_collapseMode="parallax">
<TextView
android:id="@+id/title"
fontPath="fonts/OpenSans-Bold.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textColor="@android:color/white"
android:textSize="@dimen/large_text"/>
<RatingBar
android:id="@+id/rating_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) 尝试构建一个带有collapsingtoolbarlayout和视图元素的Android应用程序,该视图元素始终直接位于工具栏底部的下方.
我想我只是在整个appbarlayout中弄乱我的组织,但我似乎无法弄清楚正确的排序.
任何帮助都会很棒!谢谢-
这是我的Activity xml
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="244dp"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:collapsedTitleTextAppearance="@style/CollapsedTheme"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleGravity="center|bottom"
app:expandedTitleMarginBottom="20dp"
app:expandedTitleMarginEnd="20dp"
app:expandedTitleMarginStart="20dp"
app:expandedTitleTextAppearance="@style/ExpandedTheme"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:theme="@style/ToolbarColoredBackArrow">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="180dp"
android:orientation="vertical">
</LinearLayout>
<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>
<include layout="@layout/content_product" />
Run Code Online (Sandbox Code Playgroud)
而我正试图加入
<RelativeLayout
android:layout_below="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="@color/blue"/>
Run Code Online (Sandbox Code Playgroud)
因此它始终保持在工具栏下方,但是当collapsingtoolbarlayout滚动到屏幕顶部时,它会一直停留在屏幕下方.
我想在特定的操作上保持这种布局:

如今,我可以CoordinatorLayout通过对其进行滑动来折叠或扩展它.我想阻止这种行为.
android material-design android-coordinatorlayout android-collapsingtoolbarlayout
我有一个折叠的工具栏布局。我已经在上面显示了图表。因此,如果图表中没有要显示的项目,我想将折叠工具栏布局显示为折叠、隐藏或关闭。应该只显示工具栏和标题,而不是图表。
这是视图:
我只想显示左侧有菜单图标的工具栏。
布局代码:
<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" …Run Code Online (Sandbox Code Playgroud) 我在尝试设置 AppBarLayout 参数时遇到 ClassCastException。下面是我的 XML 代码
<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="com.example.testapp.ConsoleActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="280dp"
android:theme="@style/AppTheme.AppBarOverlay"
android:id="@+id/app_bar_layout">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="220dp"
android:id="@+id/app_bar_account_cards_pager"
app:layout_collapseMode="parallax"
android:layout_marginTop="?attr/actionBarSize" />
<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/AppTheme.PopupOverlay"
app:layout_collapseMode="pin" />
</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:clipToPadding="false"
android:id="@+id/nested_scroll_bar"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<include layout="@layout/content_console"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用以下 java 代码获取 AppBarLayoutParams 的实例
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
AppBarLayout.LayoutParams p = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
p.setScrollFlags(0);
toolbar.setLayoutParams(p);
Run Code Online (Sandbox Code Playgroud)
但我正在接受java.lang.ClassCastException: android.support.design.widget.CollapsingToolbarLayout$LayoutParams cannot be cast to android.support.design.widget.AppBarLayout$LayoutParams这条线 …
android android-toolbar android-collapsingtoolbarlayout android-appbarlayout
我正在尝试为我的布局实现视差效果.它有效,但我还需要一件事.这是我的代码
<?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:id="@+id/coordinator_layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_main"
android:layout_width="match_parent"
android:layout_height="@dimen/height_toolbar_header_experiment_result"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:titleEnabled="false">
<ImageView
android:id="@+id/image_view_tab_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/experiment_result_header"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.3"
android:background="@android:color/black"
android:fitsSystemWindows="true"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_tab_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="top"
android:layout_marginBottom="?actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:tabIndicatorColor="@android:color/white"
app:tabSelectedTextColor="@android:color/white"
app:tabTextColor="@color/whitesmoke"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
这工作正常,但我只能在滑动标题ImageView(image_view_tab_header)时滚动/折叠工具.当我尝试向内滑动ViewPager它不会折叠工具栏.只有当我尝试在标题内部向上滑动时.
如何在viewpager中滑动时启用工具栏的折叠?
谢谢
android android-fragments android-viewpager android-collapsingtoolbarlayout android-appbarlayout
我试图在折叠工具栏展开或折叠时显示标题。然而,在任何这些状态下,标题总是有一个移动动画:
如何完全摆脱动画并使标题保持在一个位置?
我尝试将 titleEnabled 设置为 false 但这仅禁用标题并且不再显示它
<android.support.design.widget.CollapsingToolbarLayout
app:titleEnabled="false"
...
>
Run Code Online (Sandbox Code Playgroud)
编辑1:我的完整布局: _______________________________________________________________________
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorWhite">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="@color/standardBlue"
app:title="Title"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout
android:id="@+id/activityprofile_topsection"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/activityprofile_coverpicture"
android:layout_width="match_parent"
android:layout_height="120dp"
android:background="@color/standardBlue" />
<ImageView
android:id="@+id/activityprofile_profilepicture"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="70dp"
android:background="@drawable/profile_picture_white_border" />
<TextView
android:id="@+id/activityprofile_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/activityprofile_profilepicture"
android:layout_marginStart="15dp"
android:layout_marginTop="5dp"
android:text="Username"
android:textColor="@color/colorBlackFont"
android:textSize="16sp" />
</RelativeLayout>
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:contentInsetStart="0dp"
app:layout_collapseMode="pin">
<ImageView
android:id="@+id/activityprofile_backbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/actionBarItemBackground"
android:padding="15dp"
app:srcCompat="@drawable/icon_back_white_arrow" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout> …Run Code Online (Sandbox Code Playgroud) 我正在尝试将“折叠的工具栏”的标题居中。但是基本布局本身似乎存在一些错误。标题由于某些原因而有偏移。无法找出解决方法。同样,似乎也没有属性将负的边距/填充应用于collapsedTitle。
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator_layout"
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:orientation="vertical">
<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/XXXXAppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:collapsedTitleGravity="center"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleGravity="top|center_horizontal"
app:expandedTitleMarginTop="-10dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:title="REGISTER">
<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/XXXXAppTheme.PopupOverlay"/>
<ImageView
android:id="@+id/ivContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/white_background"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_collapseMode="parallax"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<FrameLayout
android:id="@+id/flContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我想在CollapsingToolbarLayout展开时隐藏ImageView(徽标),而仅在CollapsingToolbarLayout折叠时显示ImageView。(我知道如何反过来说)。
从下面的屏幕截图中可以看到。桅杆大头实际上是一个大徽标,图像在左侧,然后在公司名称在右侧。在折叠模式下,我只想显示徽标的小缩略图。
请问如何用XML或代码完成此操作?下面的代码和屏幕截图:
<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:scaleType="fitCenter"
android:adjustViewBounds="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbarlayout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="@color/colorPrimary">
<ImageView
android:id="@+id/mast_logo_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.9"
android:src="@drawable/uj_logo_rectangle_orange_background" />
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="100dp"
app:contentInsetStart="40dp"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:orientation="horizontal"
app:layout_collapseMode="pin">
<ImageView
android:id="@+id/thumbnail_logo_main"
android:layout_width="40dp"
android:layout_height="40dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:layout_marginTop="50dp"
android:layout_marginLeft="10dp"
android:src="@drawable/uj_rgb_logo_01" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="4">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:paddingTop="20dp"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:textColor="#fff"
android:textStyle="bold"
android:text="Courses & Programmes"/>
<android.support.v7.widget.SearchView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageView …Run Code Online (Sandbox Code Playgroud)