2016-03-27 14 views
0
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout" 
     android:fitsSystemWindows="true" 
     tools:context="com.example.sujin.trinity.HomePageActivity"> 

     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/AppTheme.AppBarOverlay" 

      android:background="#ffffff"> 

      <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_home_page" /> 
     <fragment 
      android:id="@+id/fragment_navigation_drawer" 
      android:layout_width="350dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      app:layout="@layout/fragment_navigation_drawer" 
      tools:layout="@layout/fragment_navigation_drawer" 
      android:name="com.example.sujin.trinity.NavigationDrawerFragment" 
      /> 
      </android.support.v4.widget.DrawerLayout> 

Hier ist die content Layoutdatei lösen:Wie AppBarLayout mit DrawerLayout Fehler

 <?xml version="1.0" encoding="utf-8"?> 
     <RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     tools:context="com.example.sujin.trinity.HomePageActivity" 
     tools:showIn="@layout/activity_home_page"> 

     <CalendarView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/calendarView" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="182dp" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="Large Text" 
      android:id="@+id/textView" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="84dp" 
      android:textColor="#000000" /> 
    </RelativeLayout> 

When <code>android:background="#ffffff"</code> is used, following output is observed but the other elements like TextView are not visible.

[When <code>android:background</code> is not used, following output is observed but the other elements like TextView are not visible.

Wenn android:background="#ffffff" verwendet wird, erste Ausgabe beobachtet wird, aber der andere Elemente wie TextView sind nicht sichtbar.

Wenn android:background="#ffffff" nicht verwendet wird, wird die zweite Ausgabe beobachtet, aber die anderen Elemente wie TextView sind nicht sichtbar. Wie löse ich diesen Fehler?

+0

Welche TextView möchten Sie zeigen? Bitte fügen Sie Ihr Inhaltslayout hinzu. –

+1

Das 'AppBarLayout' muss innerhalb des Hauptinhalts' ViewGroup' liegen. Im Moment handelt es sich um den Hauptinhalt selbst. Setzen Sie das 'AppBarLayout' und das' 'd Layout in eine andere' ViewGroup'; beispielsweise ein LinearLayout oder ein RelativeLayout. –

+0

@ cricket_007 Ich habe das Inhaltslayout –

Antwort

0

Warum Fragment für fragment_navigation_drawer verwenden ???? Verwendung von Standard-Code von Android Studio, wie unten:

<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

    <include 
     layout="@layout/app_bar_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/nav_header_main" 
     app:menu="@menu/activity_main_drawer" /> 
</android.support.v4.widget.DrawerLayout> 

und machen eine andere XML für Ihre Symbolleiste und Inhalt wie unten:

<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:fitsSystemWindows="true" 
    tools:context=".MainActivity"> 

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

</android.support.design.widget.CoordinatorLayout> 

Ich hoffe, dass es Ihnen helfen kann.

Verwandte Themen