gpt4 book ai didi

java - 应用栏滚动且灵活空间不起作用

转载 作者:行者123 更新时间:2023-12-02 09:31:36 26 4
gpt4 key购买 nike

我正在开发一个应用程序,我必须在其中显示内容列表。另外,我必须添加具有灵活空间的应用程序栏滚动。一切工作正常,但滚动行为不起作用。已经在互联网上搜索过,但没有任何效果。

这是我的 xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="200dp">

<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/sky_blue"
app:expandedTitleGravity="top"
app:layout_scrollFlags="scroll|exitUntilCollapsed">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="70dp"
app:layout_collapseMode="pin">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginStart="50dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="50dp"
android:background="@drawable/rounded_edittext"
android:gravity="center_vertical"
android:orientation="horizontal">

<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="20dp"
android:src="@drawable/ic_search" />

<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp"
android:layout_marginEnd="20dp"
android:background="@null"
android:fontFamily="@font/opensans_regular"
android:hint="Search"
android:inputType="text"
android:maxLines="1"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textSize="15sp" />
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>

<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView"
tools:listitem="@layout/custom_movie_row"
android:layout_marginTop="200dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/></androidx.constraintlayout.widget.ConstraintLayout>

这就是我的 Activity 使用上述代码的样子。 Activity

Recycler View 工作正常,但它不会折叠 AppBar。

这是我想要在 Activity 中实现的行为

enter image description here

最佳答案

将父 View 组作为协调器布局而不是约束布局。

关于java - 应用栏滚动且灵活空间不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57913773/

26 4 0