1. 개요

- 사이드 메뉴를 구현하기 위한 레이아웃

2. 핵심

- DrawerLayout아래 같은 레이어의 자식을 생성하고 그 중 layout_gravity를 갖는 뷰가 사이드 메뉴가 된다.

- 설정해둔 gravity_layout의 방향을 통해 사이드메뉴를 불러올 수 있다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawerLayout"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff"
    tools:context=".Main.StoreMainActivity">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
 
        <android.support.v7.widget.Toolbar
            android:gravity="right"
            android:layout_gravity="right"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="#fff">
 
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="응답하라경기북부"
                android:layout_gravity="center"
                android:id="@+id/toolbar_title"
                android:textStyle="bold"
                android:textSize="20sp"
                />
        </android.support.v7.widget.Toolbar>
 
        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
 
        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>
 
    <LinearLayout
        android:id="@+id/layout_storemain_sidemenu"
        android:layout_gravity="left"
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="match_parent">
        <Button
            android:text="메뉴1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
 
    </LinearLayout>
 
</android.support.v4.widget.DrawerLayout> 
cs

 

1
drawerLayout.openDrawer(Gravity.LEFT);
cs

+ Recent posts