【发布时间】:2018-01-28 18:23:55
【问题描述】:
在我的应用程序中,我使用 android.support.v7.widget.Toolbar 作为工具栏。
这是我的布局
<?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"
tools:context="com.todo.app.MainActivity"
style="@style/MainActivityBg">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/AppTheme.AppBarOverlay"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
style="@style/AppTheme.ActionBar"/>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main"/>
和
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main"
tools:context="com.todo.app.MainActivity"
android:layout_marginTop="5dp"> <!-- for adding some space between the toolbar and the rest, and this is the cause of the problem! -->
<android.support.v7.widget.RecyclerView
android:id="@+id/task_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
我尝试在工具栏和视图的其余部分之间添加一些空间。为此,我将 marginTop 中的 5dp 添加到视图正下方的布局中。这导致了这个问题: 当我滚动视图时,工具栏下还有一些空间。
在我的样式文件 xml 中,没有用于边距或填充的样式。 如何在工具栏和其余部分之间添加一些空间而不触发此问题(当我滚动视图时)?
【问题讨论】:
-
你确定你明确添加的marginTop不是原因吗?这有什么意义?
-
好吧,我的错!问题是由于 marginTop ^^ 但实际上我试图在工具栏和它下面的其余视图之间添加一些空间。但是当我应用这个 marginTop 时,就会出现上述问题
标签: android android-layout android-toolbar android-resources