2016-11-03 1 views
2

Activity이라는 간단한 앱이 있습니다. 현재 Viewstoolbar과 중복됩니다도구 모음과 겹치는보기

Image of toolbar

내가 Views하지 그것으로는 toolbar 아래에 가고 싶어. 어떻게해야합니까?

activity_main.xml

:

<?xml version="1.0" encoding="utf-8"?> 
<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"> 

    <android.support.design.widget.CoordinatorLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" /> 

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

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

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="asdasdasdasd"/> 

</android.support.v4.widget.DrawerLayout> 

styles.xml :

<resources> 

    <style name="AppTheme.NoActionBar"> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
     <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
     <item name="android:statusBarColor">@android:color/transparent</item> 
    </style> 
</resources> 
+0

'layout_below'? –

+0

도구 모음을 drawerlayout 밖으로 옮기려고 했습니까? – linhtruong

답변

3

DrawerLayout을 사용하는 올바른 방법이 아닙니다. 첫 번째보기에는 사용자에게 표시 할 내용이 있어야합니다. 나중에 서랍을 추가 할 수 있습니다. 예를 들어 다음을 사용할 수 있습니다.

<?xml version="1.0" encoding="utf-8"?> 
<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"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <android.support.design.widget.CoordinatorLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" /> 

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

    <TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="asdasdasdasd"/> 
</LinearLayout> 

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

</android.support.v4.widget.DrawerLayout> 
+0

이렇게하면 문제가 해결되었습니다. 감사합니다! – gibs

0

도구 모음 후 CoordinatorLayout 내부의 텍스트 뷰를 넣어합니다 (windowDrawsSystemBarBackgrounds주의). 이것이 활동의 ​​주요 내용이 나오는 곳입니다. Android Studio 템플릿을 사용하는 경우 content_main.xml 파일이 생성되고 include 파일이 생성됩니다. 예를 들어

물론

 <include layout="@layout/content_main" /> 

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

, 당신은 포함 태그 또는 별도의 XML 레이아웃없이 동일한 기능을 수행 할 수 있지만, 당신이 할 경우는 청소기 파일 구성입니다.


현재, 당신은 DrawerLayout의 일환으로 텍스트 뷰를 가지고 당신이 NavigationView 확장으로 아마를 통해 이동합니다. 분명히, 당신이 원하는 것이 아닙니다.

+0

TextView를 CoordinatorLayout에 넣고 툴바에 계속 넣습니다. – gibs

관련 문제