【发布时间】:2015-12-10 00:53:46
【问题描述】:
我正在使用 android support design 'com.android.support:design:22.2.1' 我的问题是当滚动中没有内容时,折叠工具栏仍然启用折叠动作。如果滚动中没有内容,我需要删除视图的折叠。
我的 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 问题:
我已完成禁用和启用视图折叠。我使用这行代码来禁用折叠:
AppBarLayout.LayoutParams appbarParams = (AppBarLayout.LayoutParams) collapsingToolbar.getLayoutParams();
appbarParams.setScrollFlags(0);
collapsingToolbar.setLayoutParams(p);
问题是 appbar 强制将滚动标志的高度设置为 0。我尝试使用 appbar.setElevation(0) 但它没有效果。如何从我的应用栏中删除海拔高度?
【问题讨论】:
-
app:layout_scrollFlags = "none"。这行得通吗?
-
我怎样才能以编程方式做到这一点
-
这里有一个很好的评论stackoverflow.com/q/32398500/2506817:“当我使用
NestedScrollView(带有wrap_content属性)作为主容器并使用TextView作为子容器时,AppBarLayout可以正常工作并且不滚动。”
标签: android scroll toolbar android-collapsingtoolbarlayout