gpt4 book ai didi

java - CollapsingToolBar 不起作用后添加 ScrollView

转载 作者:行者123 更新时间:2023-12-02 11:03:15 25 4
gpt4 key购买 nike

在我的 CountryActivityInfo.java 中,我有一个折叠工具栏,其宽度和高度都设置为 match-parent,因此它可以占据整个手机屏幕。当我向上滚动时,工具栏会获得固定的 200dp 高度。

现在,它看起来像这样:

我想在工具栏折叠时出现的白色屏幕中显示一个内部有 TextView 的垂直 ScrollView 。我怎样才能做到这一点?我已经尝试过这种方法:

 <android.support.design.widget.AppBarLayout
android:id="@+id/testeparainfo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/actionBarDivider">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/backgroundcollapsedtoolbarinfo"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="exitUntilCollapsed|scroll">


<ImageView
android:id="@+id/imgCountryInfoFoto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />

<ImageView
android:id="@+id/imgCountryInfoEscuro"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:background="@drawable/background_pais_info"
android:scaleType="centerInside" />


<android.support.v7.widget.Toolbar
android:id="@+id/toolbaridinfo"
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

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

<TextView
android:id="@+id/txtNomePaisInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginStart="30dp"
android:layout_marginTop="520dp"
android:paddingBottom="10dp"
android:text="TextView"
android:textColor="@android:color/background_light"
android:textSize="35sp"
app:layout_anchor="@+id/testeparainfo"
app:layout_anchorGravity="left|bottom" />


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

</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_gravity="bottom"
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:orientation="vertical" >

<TextView
android:id="@+id/txtInfoPais"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignStart="@+id/btnArrowBackWhite"
android:layout_marginBottom="111dp"
android:text="TextView"
android:textColor="@android:color/background_light"
android:textSize="15sp"
android:visibility="invisible"
app:layout_anchor="@+id/imgCountryInfoFoto"
app:layout_anchorGravity="bottom|center" />
</LinearLayout>
</ScrollView>

但是,当我这样做时, TextView 会进入折叠工具栏并与工具栏一起折叠。顺便说一句,所有 XML 都包含在 Coordinator Layout 中!!!

最佳答案

将根更改为CoordinatorLayout

 <?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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

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

<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_scrolling" />

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

然后在 content_scrolling.xml 中使用 NestedScrollViewapp:layout_behavior="@string/appbar_scrolling_view_behavior" 使用此属性来实现正确的行为。

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

...
</android.support.v4.widget.NestedScrollView>

关于java - CollapsingToolBar 不起作用后添加 ScrollView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51172865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com