我的app(附件)宽度方面遇到问题。似乎我没有使用屏幕的整个宽度,因为我正在使用一个操作栏,而那个空间所在的位置是"设置"菜单会出现是占用屏幕的剩余宽度。有没有办法使用全宽,因为我没有使用"设置"菜单呢?
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>
感谢您对此提供任何帮助!
答案 0 :(得分:2)
您为布局赋予了宽度和高度常量,因为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>
答案 1 :(得分:2)
在content_main.xml中,请使用width 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>
答案 2 :(得分:0)
使用LinearLayout
代替android.support.design.widget.CoordinatorLayout
和android.support.constraint.ConstraintLayout
并设置orientation = "vertical"
答案 3 :(得分:0)
<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的宽度或至少在relativeLayout
之前在content_main.xml上使用工具栏