简体   繁体   English

如何删除工具栏周围的多余空间

[英]How can I remove the extra space around the toolbar

After making little changes to the example app of this library to support scrollable toolbar, some space lefts out around it and I can't figure out why. 对该库的示例应用程序进行了少许更改以支持可滚动的工具栏之后,它周围留有一些空间,我不知道为什么。

在此处输入图片说明

Layout file for this tab (tab_text_view.xml): 此选项卡的布局文件(tab_text_view.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"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@null">

    <de.mrapp.android.util.view.UnfocusableToolbar
      android:id="@+id/toolbar"
      android:layout_width="match_parent"
      android:layout_height="?attr/actionBarSize"
      android:background="@android:color/transparent"
      android:focusable="false"
      android:theme="?attr/toolbarTheme"
      app:layout_scrollFlags="scroll|enterAlways|snap"
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

      <TextView
        android:id="@+id/file_title"
        android:layout_width="175dp"
        android:layout_height="match_parent"
        android:layout_marginLeft="55dp"
        android:ellipsize="marquee"
        android:gravity="center_vertical"
        android:singleLine="true"
        android:text="@string/file_title"
        android:fitsSystemWindows="true"
        app:contentInsetEnd="0dp"
        app:contentInsetStart="0dp"
        android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title" />

    </de.mrapp.android.util.view.UnfocusableToolbar>

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

  <android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <TextView
        android:id="@android:id/text1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:padding="@dimen/tab_padding"
        android:text="@string/lorem_ipsum"/>

  </android.support.v4.widget.NestedScrollView>

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

I only added navigation icon in the MainActivity and it's click listener. 我只在MainActivity添加了导航图标,它是单击侦听器。 Can this be a problem of insets? 这可能是插图问题吗?

If there is space to the left of the text in the toolbar, it can be removed by removing this line in the first TextView : 如果工具栏中文本的左侧有空格,可以通过在第一个TextView删除此行来删除它:

android:layout_marginLeft="55dp"

If this is not what you had in mind, a screenshot may help so I can better understand where the unwanted space is. 如果这不是您想要的,可以提供屏幕截图,这样我就可以更好地了解不需要的空间在哪里。

Use contentInsetLeft and contentInsetStart in toolbar 在工具栏中使用contentInsetLeftcontentInsetStart

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary">

     <de.mrapp.android.util.view.UnfocusableToolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorPrimary"
                    app:contentInsetLeft="0dp"
                    app:contentInsetStart="0dp"
                    app:popupTheme="@style/AppTheme.PopupOverlay">

add below code to your toolbar 将以下代码添加到工具栏

            app:contentInsetLeft="0dp"
            app:contentInsetStart="0dp"

if not work test it in normal toolbar if worked it mean problem come from library 如果不起作用,请在普通工具栏中对其进行测试,如果起作用,则意味着问题来自库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM