반응형
    
    
    
  CoordinatorLayout + AppBarLayout + NavigationDrawer
CoordinatorLayout와 결합 할 때 레이아웃 문제 AppBarLayout가 NavigationDrawer있습니다.
문제는 NavigationDrawer와 그 내용이 툴바 뒤에 숨겨져 있다는 것입니다. 나는 이미 많은 연구와 구조 조정을 시도했지만 "해결책"중 어느 것도 내 문제를 해결하지 못했습니다.
이 작은 Webm 비디오에서 데모를 찾을 수 있습니다. https://www.dropbox.com/s/i5zfc2x2ts2fws7/navigation_drawer_stackoverflow32523188.webm?dl=0
기본 스타일은 Theme.AppCompat.Light.NoActionBar입니다.
내 activity_overview.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"
    android:id="@+id/overview_coordinator_layout"
    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/ThemeOverlay.AppCompat.Dark.ActionBar">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimaryDark"
            app:layout_scrollFlags="enterAlways|scroll" />
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true"
        android:focusableInTouchMode="true">
        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/lorem_ipsum_long" />
        </android.support.v4.widget.NestedScrollView>
        <android.support.design.widget.NavigationView
            android:id="@+id/nvView"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="@android:color/white"
            app:headerLayout="@layout/nav_header"
            app:menu="@menu/navigationdrawer_main" />
    </android.support.v4.widget.DrawerLayout>
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/overview_floating_action_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:clickable="true"
        android:src="@drawable/ic_add"
        app:layout_anchor="@id/overview_coordinator_layout"
        app:layout_anchorGravity="bottom|right|end"
        app:layout_behavior="@string/fab_onscroll_behavior" />
</android.support.design.widget.CoordinatorLayout>
CoordinatorLayout은 DrawerLayout 및 NavigationView를 래핑합니다. 즉, Coordinator가 모든 항목이 배치되는 방식을 제어합니다. 다음과 같이 서랍 내부에 코디네이터를 중첩해야합니다.
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:focusableInTouchMode="true">
    <android.support.design.widget.CoordinatorLayout
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/overview_coordinator_layout"
        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/ThemeOverlay.AppCompat.Dark.ActionBar">
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimaryDark"
                app:layout_scrollFlags="enterAlways|scroll" />
        </android.support.design.widget.AppBarLayout>
        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/lorem_ipsum_long" />
        </android.support.v4.widget.NestedScrollView>
        <android.support.design.widget.FloatingActionButton
            android:id="@+id/overview_floating_action_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="16dp"
            android:clickable="true"
            android:src="@drawable/ic_add"
            app:layout_anchor="@id/overview_coordinator_layout"
            app:layout_anchorGravity="bottom|right|end"
            app:layout_behavior="@string/fab_onscroll_behavior" />
    </android.support.design.widget.CoordinatorLayout>
    <android.support.design.widget.NavigationView
        android:id="@+id/nvView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/navigationdrawer_main" />
</android.support.v4.widget.DrawerLayout>
 
그것은 그것을 해결해야합니다!
이전 답변에 추가하려면 CoordinatorLayout + child 요소를 별도의 xml 파일로 이동하여 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">
  <!-- Widget Coordinator + child elements go here -->
  <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>
참조 URL : https://stackoverflow.com/questions/32523188/coordinatorlayout-appbarlayout-navigationdrawer
반응형
    
    
    
  'programing tip' 카테고리의 다른 글
| Coffeescript 일치하지 않는내어 쓰기 오류 (0) | 2020.12.25 | 
|---|---|
| md5 암호화 및 해독 (0) | 2020.12.25 | 
| Bootstrap4를 통해 열 정렬 (0) | 2020.12.24 | 
| ReadTimeoutError : HTTPSConnectionPool (host = 'pypi.python.org', port = 443)을 pip로 해결하는 방법은 무엇입니까? (0) | 2020.12.24 | 
| Java가 SSL / HTTPS 연결에 신뢰할 수없는 인증서를 사용하도록 허용 (0) | 2020.12.24 |