【发布时间】:2015-09-18 13:51:46
【问题描述】:
我正在编写一个简单的应用程序来使用 ContentProvider,我有一个数据库、一个 ContentProvider、一个主要活动、一个使用 ContentResolver 将命令转发到 ContentProvider 的类。在 gui 上,我只想显示存储在数据库中的所有项目。我从头开始创建了这个项目,在创建 Activity 时,主布局有一个 CoordinatorLayout,带有一个 AppBarLayout,这很好,我创建了一个 ListView,除了 AppBarLayout 与 ListView 重叠,在 listview 的第一项下方被 AppBarLayout 隐藏。
我尝试在我的 ListView 中使用 android:layout_below,但它不起作用,如果我使用 android:layout_marginTop,那么我的 ListView 在 AppBarLayout 下,但我不觉得这个解决方案很好。
在 AppBarLayout 下有没有干净简单的方法让 ListView ?
在我的 activity_main 布局下方:
<?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:background="@color/holo_light_background"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/AppTheme.AppBarOverlay"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bar"/>
<android.support.design.widget.FloatingActionButton ...>
<android.support.design.widget.FloatingActionButton ...>
</android.support.design.widget.CoordinatorLayout>
【问题讨论】:
-
您没有显示足够的 XML,共享整个布局文件。
-
另外,你不应该有超过 1 个 FAB !!!
-
@Booger 实际上是整个 xml。最后一行丢失了,我添加了它,我没有给出整个浮动按钮的定义。关于 2 个浮动按钮的使用,我想你是对的,谷歌建议只使用一个浮动按钮,但他们有时会使用 2 个浮动按钮 [google.com/design/spec/components/…,这对我来说不是很清楚
-
Re FAB - 当然不适合像删除所有内容这样的破坏性操作。不过请阅读:medium.com/tech-in-asia/…
-
我是这方面的专家(查看我的简历),您应该只使用一个 FAB,当您单击 FAB 时,可以看到其他操作会从中暴露出来,这会有所不同。
标签: android listview android-appbarlayout