标签: android-collapsingtoolbarlayout

错误膨胀CollapsingToolbarLayout

我最近将支持设计库更新到最新版本,现在每个具有CollapsingToolbarLayout抛出以下异常的活动:

    java.lang.NoSuchMethodError: No static method setLayoutDirection(Landroid/graphics/drawable/Drawable;I)V in class Landroid/support/v4/graphics/drawable/DrawableCompat; or its super classes (declaration of 'android.support.v4.graphics.drawable.DrawableCompat' appears in /data/data/com.radioafrica.music/files/instant-run/dex/slice-com.android.support-support-v4-24.0.0-beta1_f8cf3ba4c70f87f407a745b9fa14a2205d0b587c-classes.dex)
Run Code Online (Sandbox Code Playgroud)

完整的错误日志如下:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.radioafrica.music/com.radioafrica.music.activity.PlaylistTracks}: android.view.InflateException: Binary XML file line #31: Binary XML file line #31: Error inflating class android.support.design.widget.CollapsingToolbarLayout at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5417) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NoSuchMethodError: No static method setLayoutDirection(Landroid/graphics/drawable/Drawable;I)V in class Landroid/support/v4/graphics/drawable/DrawableCompat; or its super classes (declaration of …
Run Code Online (Sandbox Code Playgroud)

android androiddesignsupport android-collapsingtoolbarlayout

21
推荐指数
3
解决办法
1万
查看次数

CollapsingToolbarLayout:展开时更改主页按钮颜色

我已经实现了CollapsingToolbarLayoutChris Banes示例代码中的新功能.

但是,背景图像视图的图像都具有白色背景.工具栏主题是ThemeOverlay.AppCompat.Dark.ActionBar图标也是白色的,因此当CollapsingToolbarLayout完全展开时我看不到主页按钮.

随着app:expandedTitleTextAppearance我可以设置标题字段的颜色.是否还可以设置主页按钮和菜单图标的颜色?

android android-collapsingtoolbarlayout

20
推荐指数
2
解决办法
3874
查看次数

在展开状态下没有阴影的CollapsingToolbarLayout

来自appcompat的CollapsingToolbarLayout在折叠状态下显示阴影,但在展开(或在展开过程中)阴影消失时

我的示例代码https://github.com/NaikSoftware/CollapsingToolbarWithImageAndTabs/tree/master/app

布局

<?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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="ua.naiksoftware.hidetabs.MainActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/toolbar_plus_tabs"
        app:contentScrim="@android:color/transparent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed|snap|enterAlways"
        app:titleEnabled="false"
        app:toolbarId="@+id/toolbar_wrapper">

        <ImageView
            android:id="@+id/appbar_background"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:src="@drawable/header_back"
            app:layout_collapseMode="parallax"/>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:background="@android:color/transparent"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_wrapper"
            android:layout_width="match_parent"
            android:layout_gravity="bottom"
            android:background="@android:color/transparent"
            android:layout_height="wrap_content"
            android:minHeight="@dimen/tab_layout_height">

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent"
                app:tabGravity="fill"
                app:tabIndicatorColor="@android:color/white"
                app:tabMode="scrollable"
                app:tabSelectedTextColor="@android:color/white" />
        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_add_black_24dp"
    android:layout_margin="@dimen/fab_margin"
    android:tint="@android:color/white"
    android:layout_gravity="bottom|end"
    app:elevation="@dimen/fab_elevation"
    app:layout_behavior="ua.naiksoftware.hidetabs.FabSlidingBehavior"/>
Run Code Online (Sandbox Code Playgroud)

倒塌 倒塌的状态

扩展 膨胀的国家

android shadow collapse android-collapsingtoolbarlayout

20
推荐指数
2
解决办法
7064
查看次数

使用setNestedScrollingEnabled(false)时如何避免阻止滚动?

背景

我们有一个非常复杂的布局,其中包含CollapsingToolbarLayout,以及底部的RecyclerView.

在某些情况下,我们通过在RecyclerView上调用setNestedScrollingEnabled(boolean)暂时禁用CollapsingToolbarLayout的展开/折叠.

问题

这通常很好.

但是,在某些(有点罕见的)情况下,RecyclerView上的慢速滚动会被半阻止,这意味着它会在向下滚动时尝试向后滚动.就像它有2个滚动相互争斗(向上滚动并向下滚动):

在此输入图像描述

触发此操作的代码如下:

RES /布局/ activity_scrolling.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.user.myapplication.ScrollingActivity">

    <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|snap">

            <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>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/nestedView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end">

        <Button
            android:id="@+id/disableNestedScrollingButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="disable"/>

        <Button
            android:id="@+id/enableNestedScrollingButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="enable"
            />
    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

ScrollingActivity.java

public class ScrollingActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scrolling);
        Toolbar toolbar …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview android-collapsingtoolbarlayout

20
推荐指数
1
解决办法
5269
查看次数

CollapsingToolbarLayout | 滚动和布局问题2

相关问题

CollapsingToolbarLayout | 滚动和布局问题

研究背景

我想使用2个不同的片段,这些片段允许我根据方向和屏幕大小更改布局

  1. 标题图片(目前只是一个ImageView)
  2. 可滚动内容

问题

  1. CollapsingToolbarLayout不允许我展开Toolbar Header Image

    • 它显示了大部分图像,但不是全部.Top切割,但底部是可见的.
  2. Toolbar设置为Pin,但滚动,当它被隐藏

    • 只是Header Image应该消失,但我的整个Appbar被隐藏了
  3. 滚动查看时,Expanded Toolbar有一个空视图,直到Expanded Toolbar达到其最大高度.

    • 在它Expanded Toolbar和它Toolbar自己变得隐藏之后
  4. Up Arrow不会在显示Toolbar

Layout.xml

<android.support.design.widget.CoordinatorLayout 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:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="16dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|enterAlways">

            <ImageView
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/download"

                android:scaleType="centerCrop" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/anim_toolbar" …
Run Code Online (Sandbox Code Playgroud)

xml android material-design android-design-library android-collapsingtoolbarlayout

19
推荐指数
1
解决办法
3万
查看次数

NestedScroll中的可点击CardView不会触发滚动

我有一个带有CoordinatorLayout,AppBarLayout和NestedScrollView的布局,在NestedScrollView中我有多个CardViews,一切正常,直到我将CardViews设置为可点击,然后如果我在CardView中开始滚动,则滚动不起作用.

这是我的布局:

<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/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_height="256dp"
    android:layout_width="match_parent"
    app:contentScrim="?attr/colorPrimary"
    android:fitsSystemWindows="true"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary">
        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax"/>
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_height="?attr/actionBarSize"
            android:layout_width="match_parent"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
    android:id="@+id/nestedScroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_gravity="fill_vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardCornerRadius="0dp"
            app:cardUseCompatPadding="true">
            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <View
                    android:layout_width="80dp"
                    android:layout_height="80dp"
                    android:background="@color/primary" />
                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingTop="4dp"
                    android:paddingLeft="7dp"
                    android:paddingRight="7dp"
                    android:paddingBottom="7dp">
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:lines="1"
                        android:includeFontPadding="false"
                        android:text="Title1"
                        style="@android:style/TextAppearance.Medium" />
                    <TextView …
Run Code Online (Sandbox Code Playgroud)

android android-design-library android-coordinatorlayout android-collapsingtoolbarlayout android-appbarlayout

19
推荐指数
1
解决办法
3665
查看次数

如何在屏幕方向更改后恢复折叠工具栏布局状态

我一直在寻找我的问题的解决方案一段时间,但没有找到解决方案.

我希望在屏幕方向改变后恢复片段的布局.我有折叠工具栏布局与横幅图像.屏幕旋转后,我的工具栏总是展开,我想恢复它的行为.我怎样才能做到这一点?

layout android toolbar android-collapsingtoolbarlayout

19
推荐指数
3
解决办法
4440
查看次数

滚动后,CoordinatorLayout在底部留下空白空间

我正在尝试使用CoordinatorLayout实现Google的最新设计技巧,并且在滚动和视差效果方面存在问题.

显示活动后,一切看起来都不错,但是当我尝试滚动时会出现问题.看起来底部视图没有正确扩展,并且在向上滚动后,下面会出现空白区域.底部视图似乎只有在顶部视图和导航栏之间初始显示时有多大.

它看起来像这样:

在此输入图像描述

相关代码:

<FrameLayout 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">

<CoordinatorLayout
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:expandedTitleMarginStart="72dp"
            app:expandedTitleMarginEnd="16dp">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_collapseMode="parallax"/>
        </CollapsingToolbarLayout>
    </AppBarLayout>

    <ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</CoordinatorLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

这种奇怪的行为是随机发生的.有时底部视图可以正常滚动,并且不会出现空白空间.我究竟做错了什么?谢谢.

android material-design coordinator-layout android-coordinatorlayout android-collapsingtoolbarlayout

19
推荐指数
2
解决办法
8610
查看次数

在CollapsingToolbarLayout上停止滚动,使其不会完全崩溃

我有一个CollapsingToolbarLayout设置,我在那里放置一个壁纸.我希望能够阻止它一直崩溃.

我已经尝试了minheight和许多其他的东西,但无法搞清楚.

如何让它停止折叠到第二个屏幕截图?

查看加载活动的时间

加载视图

期望的停止点

期望的停止点

目前的停止点

目前的停止点

android android-design-library android-collapsingtoolbarlayout

18
推荐指数
2
解决办法
1万
查看次数

CollapsingToolbarLayout未显示标题

就我而言,当我滚动列表时,工具栏会消失.我正在使用CollapsingToolbarLayout,我需要设置标题文本.但在我的情况下标题文本没有显示,即使我已经设置它(参见下面的代码).怎么了?

布局代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/coordinator"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:elevation="0dp">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|enterAlways">


            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                android:elevation="0dp"
                android:minHeight="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay">

            </android.support.v7.widget.Toolbar>

        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/app_nav_header_main"
    app:menu="@menu/main_drawer" />

</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

活动代码:

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.app_activity_with_left_panel);

    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mCollapsingToolbarLayout = (CollapsingToolbarLayout)findViewById(R.id.collapsing);
    setSupportActionBar(mToolbar);
    setTitle(getIntent().getStringExtra(TITLE));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
}

@Override …
Run Code Online (Sandbox Code Playgroud)

android android-collapsingtoolbarlayout

18
推荐指数
2
解决办法
1万
查看次数