【发布时间】:2023-03-09 23:27:02
【问题描述】:
我曾经使用 Android Studio 中的 Project-Template 设置一个折叠工具栏,并尝试在 NestedScrollView 中实现一个 ListView(参见下面的代码)
我有最新的 Android Studio 版本,并且 AVD 在 Android 9 上运行
我已经试过了
- 更改 NestedScrollView 的
android:fillViewport="true" - 实现我自己的 ListView (Collapsing Toolbar with ListView)
- 将 ListView 包装到 LinearLayout 中
我找到了几个使用RecyclerView 的解决方案,我不想使用这种方法 - 如果这是最后一种方法,我会;)。 (这是一个学校项目,我们应该只使用我们在学校学到的组件掌心)
我将跳过以下几个 XML 导入行:
<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"
tools:context=".MainScreen">
<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"
app:toolbarId="@+id/toolbar">
<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>
<fragment
android:id="@+id/fragment1"
android:name="net.mountdev.alcohollevel.EntryList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"
app:srcCompat="@drawable/ic_add_white_24dp" />
</android.support.design.widget.CoordinatorLayout>
嵌套列表视图
<android.support.v4.widget.NestedScrollView 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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainScreen"
tools:showIn="@layout/activity_main_screen">
<ListView android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"/>
</android.support.v4.widget.NestedScrollView>
目前的结果是,ListView 在 ActionBar 中不应该是(见截图)
【问题讨论】:
标签: java android android-layout listview