위의 그림과 같이 네비 버튼을 눌렀을 때 왼쪽에서 오른쪽으로 튀어나오는 레이아웃을 생성하는 예제이다.
※ 소스코드 부분
DrawerLayout drawerLayout;
View drawerView;
ImageButton btn_actionBar
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
drawerView = (View)findViewById(R.id.drawer);
btn_actionBar = (ImageButton) findViewById(R.id.btn_actionBar);
---그 외 소스 내용 ---
}
OnClickListener listener = new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btn_actionBar:
drawerLayout.openDrawer(drawerView);
break;
default:
break;
}
}
};
※ 레이아웃 부분
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
-------- 화면에 나타날 레이아웃 퍼블 부분 -------------
</LinearLayout>
-------- 왼쪽에서 튀어나올 멀티 윈도우 부분 --------------
<LinearLayout
android:id="@+id/drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/background_dark"
android:orientation="vertical"
android:padding="5dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Drawer" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<Button
android:id="@+id/closedrawer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Close Drawer" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
'플밍 is 뭔들 > 안드로이드' 카테고리의 다른 글
[안드로이드] EditText 자동 포커스, 키보드 자동실행 막는법, 키보드 실행시 화면 사이즈 재설정 (0) | 2017.02.11 |
---|---|
[안드로이드] Back(뒤로가기) 버튼 2번 터치시 앱 종료하기 (0) | 2017.02.11 |
[안드로이드] dp -> px / px -> dp로 변환하기 (0) | 2017.02.11 |
[안드로이드] dp, dip, sp, px의 차이 (0) | 2017.02.11 |
[안드로이드] 레이아웃 중첩, 겹치기 삭제 (0) | 2017.01.23 |