我想隐藏我的AppBarLayout以动态添加视图,该视图将占用屏幕的高度。为此,我想通过将AppBarLayout的可见性设置为GONE来暂时删除视图。该视图不可见,但会在屏幕上占用空间(屏幕高度的一半)。
我的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:id="@+id/coordinatorFriendProfil"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#81D4FA"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/fProfilAppBar"
android:layout_width="match_parent"
android:layout_height="250dp"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/fProfilCollapsing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#B3E5FC"
android:gravity="center"
android:orientation="vertical"
app:contentScrim="#03A9F4"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:id="@+id/fProfilUserInfo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<com.neden.neden.RoundedImageView
android:id="@+id/ivFriendPicture"
android:layout_width="150sp"
android:layout_height="150sp"
android:layout_gravity="center"
android:fitsSystemWindows="true"
android:src="@drawable/photo"
app:border_color="#64B5F6"
app:border_width="4dp"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7" />
<TextView
android:id="@+id/fProfilName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="15pt" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/fProfilToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/fProfilContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
我想添加图像以显示问题,但由于我的声誉,我不能。对不起,英语不好,我的英语说得不太好。
您的问题是由此行引起的
app:layout_behavior="@string/appbar_scrolling_view_behavior"
您将必须以编程方式在CoordinatorLayout上进行设置,而不是在具有该字段的实际容器片段上进行设置。
这里是
mContainer = (FrameLayout) findViewById(R.id.main_content_container);
CoordinatorLayout.LayoutParams params =
(CoordinatorLayout.LayoutParams) mContainer.getLayoutParams();
params.setBehavior(null);
mContainer.requestLayout();
如果要使其再次滚动,则>
params.setBehavior(new AppBarLayout.ScrollingViewBehavior());
尝试将AppBarLayout的高度设置为零
我能够通过将所有内容从CollapsingToolbarLayout
(CTL)移到Toolbar
来解决此问题,使Toolbar
成为CTL的唯一后裔。然后,我将CTL的高度设置为wrap_content
,并使用我使用的代码toolbar.setVisibility(View.GONE)
。请注意,您可能想要更改Toolbar
内的布局,在其子元素周围添加一些包装器,例如RelativeLayout
或其他内容。
您可以尝试