应用程序不使用全屏宽度(Actionbar)

App does not use full width of screen (Actionbar)

关于我的应用程序(附件)的宽度,我遇到了问题。似乎没有使用屏幕的整个宽度,因为我使用的是操作栏,并且 "Settings" 菜单出现的 space 占据了屏幕的剩余宽度。有没有什么办法可以使用全宽,因为我根本没有使用 "Settings" 菜单?

app_bar_main.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"
    xmlns:tools="http://schemas.android.com/tools"
    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: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" />

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

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

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

content_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.simple.activities.MainActivity"
    tools:showIn="@layout/app_bar_main">

    <RelativeLayout
        android:id="@+id/master_fragment"
        android:layout_width="368dp"
        android:layout_height="495dp"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp">

    </RelativeLayout>
</android.support.constraint.ConstraintLayout>

current_fragment.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.simple.fragments.Notifier">

    <!-- TODO: Update blank fragment layout -->

    <TabHost
        android:id="@+id/tab_host"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <include android:id="@+id/layout1"
                    layout="@layout/activity_hour_notification"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"></include>

                <include android:id="@+id/layout2"
                    layout="@layout/activity_minute_notification"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"></include>

            </FrameLayout>
        </LinearLayout>
    </TabHost>
</FrameLayout>

感谢您对此的任何帮助!

使用 LinearLayout 代替 android.support.design.widget.CoordinatorLayoutandroid.support.constraint.ConstraintLayout 并设置 orientation = "vertical"

您为布局指定了宽度和高度常量,对于 ConstraintLayout match_parent 指定 0dp 并添加所有必要的约束

<RelativeLayout
        android:id="@+id/master_fragment"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        >

    </RelativeLayout>

在content_main.xml中请使用宽度match_parent

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.simple.activities.MainActivity"
    tools:showIn="@layout/app_bar_main">

    <RelativeLayout
        android:id="@+id/master_fragment"
        android:layout_width="match_parent"
        android:layout_height="495dp"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp">

    </RelativeLayout>
</android.support.constraint.ConstraintLayout>
<RelativeLayout
        android:id="@+id/master_fragment"
        android:layout_width="368dp"
        android:layout_height="495dp"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp">

这里你让特定值的宽度与父级不匹配,包含工具栏和选项卡的片段布局将采用该宽度,所以你应该使宽度为 master_fragment match_parent 或者至少使用工具栏content_main.xml 在 relativeLayout 之前