【问题标题】:Toolbar overlapping with elements in Android工具栏与 Android 中的元素重叠
【发布时间】:2016-05-02 03:08:14
【问题描述】:

我正在我的应用中实现一个列表视图。我正在尝试为 android 6.0 构建我的应用程序并选择了主题“DarkActionBar”。我现在在 activity_main.xml 中有这段代码。

<?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:fitsSystemWindows="true"
    tools:context="com.mycompany.www.mynotes.MainActivity">

    <android.support.design.widget.AppBarLayout
        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"
            app:popupTheme="@style/AppTheme.PopupOverlay" />
    </android.support.design.widget.AppBarLayout>

    <ListView
        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </ListView>

</android.support.design.widget.CoordinatorLayout>

我刚刚在这段代码中添加了一个列表视图(替换了一个文本视图)。当我创建我的项目时,其余代码已经存在。

现在我正在列表视图中随机添加一些项目。 现在的问题是,最顶部的列表视图项位于工具栏后面,如下图所示。如何解决?我希望这个列表视图从工具栏下方开始。

【问题讨论】:

  • 这个问题和Android Studio有什么关系? Android Studio 是用于 Android 开发的 IDE。您的问题与 IDE 无关。

标签: java android android-studio


【解决方案1】:

您必须将app:layout_behavior 添加到您的LiveView

<ListView
        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

【讨论】:

  • 谢谢,它有效。但是你能告诉我,这个 appbar_scrolling_view_behavior 是从哪里来的。 strings.xml 中没有这样的资源。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-02-20
  • 2016-03-03
  • 2015-05-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-21
相关资源
最近更新 更多