[英]remove default margin bottom from Toolbar
在我的应用程序中,我将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中,没有用于边距或填充的样式。 如何在工具栏和其余工具之间添加一些空间而又不会触发此问题(滚动视图时)?
基于xml文件,在我看来:
<android.support.constraint.ConstraintLayout
...
android:layout_marginTop="5dp">
是裁剪RecyclerView
内容的原因。
当您设置layout_marginTop
之间AppBarLayout
和上部边缘ConstraintLayout
出现5dp
高空白。
您可以通过为开发人员打开Android选项之一来确认这一点: Show Layout Bounds 。
对于您想要实现的效果,请尝试删除android:layout_marginTop
并将RecyclerView
设置为android:paddingTop
,但还要将android:clipToPadding
设置为false 。 检查此SO答案中的gif。
<android.support.v7.widget.RecyclerView
android:id="@+id/task_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="5dp"
android:clipToPadding="false" />
这将使您可以在可滚动内容的开头添加所需的空间,但可以防止裁剪项目。
如果5dp的上边距不是问题,可能是工具栏高程,请尝试将4dp更改为更高的值,然后检查是否更改了问题。 你可以用保证金顶试试吗? 有时也有消极作用。 在工具栏的按钮上放置一个空白,然后检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.