2017-08-16 100 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