代码之家  ›  专栏  ›  技术社区  ›  Araw

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

  •  1
  • Araw  · 技术社区  · 7 年前

    当涉及到我的应用程序(附件)的宽度时,我面临一个问题。因为我使用的是actionbar,所以似乎没有使用屏幕的全宽,而“Settings”(设置)菜单出现的空间占用了屏幕的剩余宽度。既然我没有使用“设置”菜单,有没有办法使用全屏?

    app\u bar\u 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>
    

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

    当前_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>
    

    谢谢你在这方面的帮助!

    enter image description here

    4 回复  |  直到 7 年前
        1
  •  2
  •   Muthukrishnan Rajendran    7 年前

    对于ConstraintLayout,您为布局指定了宽度和高度常数 match_parent

    <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>
    
        2
  •  2
  •   vishal jangid    7 年前

    在content_main中。xml请使用width match\u 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>
    
        3
  •  0
  •   Athar Iqbal    7 年前

    LinearLayout android.support.design.widget.CoordinatorLayout android.support.constraint.ConstraintLayout orientation = "vertical"

        4
  •  0
  •   ahmed shaaban    7 年前
    <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\u fragment的宽度与父项匹配,或者至少使用content\u main上的工具栏。相对映射之前的xml