Android AppBarLayout 与列表视图重叠 [英] Android AppBarLayout overlaps listview

查看:22
本文介绍了Android AppBarLayout 与列表视图重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个简单的应用程序来与 ContentProvider 一起玩,我有一个数据库、一个 ContentProvider、一个主要活动、一个使用 ContentResolver 将命令转发到 ContentProvider 的类.在 gui 上,我只想显示存储在数据库中的所有项目.我从头开始创建了这个项目,在创建 Activity 时,主布局有一个 CoordinatorLayout 和一个 AppBarLayout,这很好,我创建了一个 ListView 并且一切正常,除了 AppBarLayout 与 ListView 重叠,在列表视图的第一项下方被 AppBarLayout 隐藏.

I am writing a simple app to play with ContentProvider, I have a db, a ContentProvider, a main activity, a class that forwards commands to the ContentProvider using ContentResolver. On the gui I just want to display all items stored in the db. I created this project from scratch and when creating the Activity, the main layout had a CoordinatorLayout, with a AppBarLayout, and that is fine, I created a ListView and everything work except that the AppBarLayout overlaps the ListView, below the first item of the listview is hiding by the AppBarLayout.

我尝试将 android:layout_below 用于我的 ListView 但它不起作用,如果我使用 android:layout_marginTop 那么我的 ListView 在 AppBarLayout 下,但我没有觉得这个解决方案不错.

I tried to use android:layout_below for my ListView but it does not work, if I use android:layout_marginTop then my ListView is under the AppBarLayout but I do not find this solution nice.

在 AppBarLayout 下有没有简单的 ListView 方法?

Is there no clean easy way to have ListView under the AppBarLayout?

在我的 activity_main 布局下方:

below my activity_main layout:

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

推荐答案

简单添加

app:layout_behavior="@string/appbar_scrolling_view_behavior"

到您的列表视图

这篇关于Android AppBarLayout 与列表视图重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆