应用程序不使用全宽屏幕(Actionbar)(App does not use full width of screen (Actionbar))

编程入门 行业动态 更新时间:2024-10-11 07:25:29
应用程序不使用全宽屏幕(Actionbar)(App does not use full width of screen (Actionbar))

当涉及到我的应用程序(附件)的宽度时,我遇到了问题。 似乎我没有使用屏幕的整个宽度,因为我正在使用操作栏,并且“设置”菜单出现的空间占据了屏幕的剩余宽度。 有没有办法使用全宽,因为我还没有使用“设置”菜单?

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>

感谢您对此提供的任何帮助!

I am facing a problem when it comes to the width of my app (attachment). It seems that the full width of the screen is not used since I am using a actionbar, and that the space where the "Settings" menu would appear is taking the remaining width of the screen. Is there any way to use the full width since I am not using the "Settings" menu anyway?

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>

Thanks for any help on this one!

最满意答案

你为布局赋予了宽度和高度常量,对于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>

You gave width and height constant to the layout, for ConstraintLayout match_parent give 0dp and add all necessary constraints

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

更多推荐

本文发布于:2023-07-27 15:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1292366.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   宽屏幕   Actionbar   App   width

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!