2017-08-16 59 views
1

我面临的一个问题,当涉及到我的应用程序(附件)的宽度。由于我使用的是操作栏,所以屏幕的整个宽度似乎没有被使用,并且“设置”菜单将显示的空间将占用屏幕的剩余宽度。有没有办法使用全宽,因为我还没有使用“设置”菜单?应用程序不使用屏幕(动作条)的全宽

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> 

感谢在这一个任何帮助!

enter image description here

+1

发表您的布局XML代码以获得更好的主意。 –

+0

@abhilnair:已添加。让我知道是否有更多需要的信息。 – Araw

+0

好的,让我问一下你在content_main.xml中的分段视图。因为content_main.xml中的相对布局是空白的,所以请证明。还有一件事是,你是否正确地在工具栏下获得布局,因为你没有在你的包含布局中指定,也没有在下面提到包含布局应该出现的“什么”。请张贴您的整个屏幕截图。 –

回答

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

感谢大家!我设置了android:layout_width =“0dp”来解决问题。再次感谢! – Araw

0

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

2

在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> 
+0

Upvote as android:layout_width =“match_parent”also worked! – Araw

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

在这里你做出宽度与特定的值不匹配父和片段布局包含工具条和标签将采取宽所以你应该RelativeLayout的前做出master_fragment match_parent的宽度或至少使用工具栏上content_main.xml

相关问题