当滚动不满意时,如何禁用CollapsingToolbar的折叠? [英] How to disable CollapsingToolbar's collapse when scroll has not content?

查看:92
本文介绍了当滚动不满意时,如何禁用CollapsingToolbar的折叠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用android支持设计'com.android.support:design:22.2.1',我的问题是,当滚动中没有内容时,折叠工具栏仍会启用折叠操作.如果滚动条中没有内容,则需要删除视图的折叠.

I am using android support design 'com.android.support:design:22.2.1' my problem is that when the scroll has no content in it, the collapsing toolbar still enables the collapse action. I need to remove the collapsing of the view if the scroll has no content in it.

我的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:fitsSystemWindows="true"
                android:background="@android:color/white"
                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="match_parent"
                    android:fitsSystemWindows="true"
                    app:contentScrim="?attr/colorPrimary"
                    app:expandedTitleMarginEnd="64dp"
                    app:expandedTitleMarginStart="48dp"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed">

                    <fragment
                        android:id="@+id/pawfile_header"
                        android:name="com.lightbulb.pawesome.fragments.PawfileHeaderFragment"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10dp"
                        android:layout_marginTop="10dp"
                        android:fitsSystemWindows="true"
                        app:layout_collapseMode="parallax" />

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

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

            <fragment
                android:id="@+id/pawfile_timeline"
                android:name="com.lightbulb.pawesome.user_timeline.PawesomeUserTimelineFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

UDPATE问题:

我已经完成了禁用和启用视图折叠的工作.我使用以下代码行来禁用折叠:

I'm done with disabling and enabling the collapsing of the view. I used this line of code in order to disable the collapsing:

AppBarLayout.LayoutParams appbarParams = (AppBarLayout.LayoutParams)     collapsingToolbar.getLayoutParams();
appbarParams.setScrollFlags(0);
collapsingToolbar.setLayoutParams(p);

问题在于,appbar被强制将scrollflags的高度设置为0.我尝试使用appbar.setElevation(0),但它没有任何效果.如何从应用栏中删除海拔高度?

The problem is that the appbar is force to have the elevation of the scrollflags is set to 0. I tried using appbar.setElevation(0) but it has no effect. how can I remove the elevation from my appbar?

推荐答案

获取您的appbarlayout参考并设置setScrollFlags.

get your appbarlayout reference and set the setScrollFlags.

AppBarLayout.LayoutParams p = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
p.setScrollFlags(0);
toolbar.setLayoutParams(p);

这篇关于当滚动不满意时,如何禁用CollapsingToolbar的折叠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆