繁体   English   中英

工具栏中的自定义布局未采用全宽

[英]Custom layout in toolbar not taking full width

我在工具栏中添加了一个自定义布局,但它没有填满整个宽度,我也不知道为什么。

http://i.imgur.com/2OE7RIC.png

这是我的布局代码:

<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:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:elevation="0dp">

        <android.support.v7.widget.Toolbar
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="0dp"
            app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
            android:contentInsetStart="0dp"
            android:contentInsetLeft="0dp"
            app:contentInsetLeft="0dp"
            app:contentInsetStart="0dp">

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="360dp"
                android:background="@android:color/black"></RelativeLayout>

        </android.support.v7.widget.Toolbar>

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

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        />

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

怎么修?

如果将子工具栏的最小宽度设置为较大的值,它将增大直到填充其父视图(在本例中为工具栏)为止。

因此,请在自定义工具栏中写以下属性:

android:layout_width="match_parent"
android:minWidth="10000dp"

暂无
暂无

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

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