FrameLayout宽度不等于其父工具栏

时间:2017-08-20 08:05:13

标签: android width android-toolbar android-framelayout

frame layout showing actual width and desired width by red arrow

我在工具栏里面有一个frameLayout现在的问题是我设置了framelayout宽度以匹配专利但是它不会等于它的工具栏全长 我的代码如下

<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.ecbclass.user_activity.Home">

<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">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:id="@+id/app_title_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:text="ECB Class"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="#FFF"
                android:textStyle="bold" />

            <android.support.v7.widget.SearchView
                android:id="@+id/search_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center_vertical"
                android:elevation="5dp"
                android:hapticFeedbackEnabled="true"
                android:layoutDirection="rtl">

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

        </FrameLayout>
    </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_home" />

请建议我解决这个问题的方法

1 个答案:

答案 0 :(得分:1)

contentInsetLeft中添加几行(contentInsetStartToolbar),您就完成了: -

<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:contentInsetLeft="0dp"
        android:contentInsetStart="0dp"
        app:contentInsetLeft="0dp"
        app:contentInsetStart="0dp" />