Android AppBarLayout与listview重叠 [英] Android AppBarLayout overlaps listview

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

问题描述

我正在编写一个与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"

到您的ListView

to your ListView

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

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