¾È±Ô °øºÎ¹æ

Android > SlidingDrawer - ¸¸µé±â

µî·ÏÀÏ : 2017-07-05 18:41 Á¶È¸¼ö : 53,618

    

SlidingDrawer ¶õ, À§ ±×¸²°ú °°ÀÌ ¼­¶ø°ú °°ÀÌ ¼û°Ü ÀÖ´Ù°¡ µå·¡±× ¹× Ŭ¸¯ÇÏ¿© ¿­¾î¼­ »ç¿ëÇÒ ¼ö ÀÖ´Â À§Á¬À» ¸»ÇÕ´Ï´Ù.

FrameLayout / RelativeLayout ÀÌ SlidingDrawer¸¦ »ç¿ëÇϱ⿡ ÀûÇÕÇÑ ·¹À̾ƿôÀÔ´Ï´Ù.

LiearLayoutÀ̳ª TableLayout¿¡´Â »ç¿ëÇÒ ¼ö ¾ø½À´Ï´Ù.

¿©±â¼­´Â RelativeLayout¸¦ ¹ÙÅÁÀ¸·Î ¸¸µé¾î º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.

SlidingDrawer ÀÇ ¼Ó¼ºÀº ¾Æ·¡¿Í °°½À´Ï´Ù.
 
android:allowSingleTap="true" SlidingDrawerÀÇ handleÀ» Ŭ¸¯ ½Ã ¿­ ¼ö ÀÖµµ·Ï ÇÒ °ÍÀÎÁö¿¡ ´ëÇÑ ¼Ó¼ºÀ̸ç, µðÆúÆ®´Â true ÀÔ´Ï´Ù. false¼³Á¤ ½Ã µå·¡±×¸¦ ÅëÇؼ­¸¸ ¿­ ¼ö ÀÖ½À´Ï´Ù.
android:animateOnClick="true" Ŭ¸¯ÇÏ¿© ¼­¶øÀ» ¿­ ¶§ ¹Ì²ô·¯Áö´ÂµíÇÑ ¾Ö´Ï¸ÅÀ̼ÇÀ» »ç¿ë ÇÒ°ÍÀÎÁö ¼³Á¤ÇÏ´Â ¼Ó¼ºÀ̸ç, µðÆúÆ®´Â trueÀÔ´Ï´Ù. ±×·±µ¥ test°á°ú true/falseÀÇ Â÷ÀÌÁ¡ÀÌ ¾ø¾ú½À´Ï´Ù.¤Ñ¤Ñ;;
android:bottomOffset="5dp" ¼­¶øÀ» ´Ý¾ÒÀ»¶§ handle°ú ºÎ¸ð ¾Æ·¡ÂÊ°úÀÇ °£°ÝÀÔ´Ï´Ù. °ªÀÌ Ä¿Áú¼ö·Ï handleÀÌ ¾Æ·¡·Î ³»·Á°¡°í ÀÛ¾ÆÁú¼ö·Ï handleÀÌ À§·Î ¿Ã¶ó°©´Ï´Ù.
android:content="@+id/content content. Áï, SlidingDrawer¸¦ ¿­¾úÀ» ¶§ÀÇ ³»¿ë¹°ÀÇ ·¹À̾ƿôÀ» ¼³Á¤ÇØÁÖ´Â ¼Ó¼ºÀ̸ç, ¿©±â¼­´Â ³»ºÎ¿¡ ¸¸µç LinearLayoutÀ» ¼³Á¤ÇÏ¿´½À´Ï´Ù.
android:handle="@+id/handle" handleÀ» ¼³Á¤ÇÏ´Â ¼Ó¼ºÀ̸ç, ¿©±â¼­´Â ÇϳªÀÇ À̹ÌÁöºä·Î ¼³Á¤ÇÏ¿´½À´Ï´Ù.
android:orientation="vertical" SlidingDrawerÀÇ ¹æÇâÀ̸ç, horizontalÀÎ °æ¿ì ¿ìÃø¿¡¼­ ¿­¸®´Â SlidingDrawer¸¦, verticalÀÎ °æ¿ì ¾Æ·¡¿¡¼­ ¿­¸®´Â ¼Ó¼ºÀ» ¼³Á¤ÇÕ´Ï´Ù. µðÆúÆ®´Â verticalÀÔ´Ï´Ù.
android:topOffset="60dp" SlidingDrawer¸¦ ¿­¾úÀ» °æ¿ì ºÎ¸ð ·¹À̾ƿô°úÀÇ °£°ÝÀÔ´Ï´Ù. ¸¸¾à 0À¸·Î ¼³Á¤ ½Ã ºÎ¸ð ·¹À̾ƿôÀ» ¿ÏÀüÈ÷ µ¤°Ô µË´Ï´Ù.


1. activity_main.xml ÆÄÀÏÀ» ÀÛ¼ºÇÕ´Ï´Ù.

layout/activity_main.xml

 
	
	<?xml version="1.0" encoding="utf-8"?>
	<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
	    android:layout_width="fill_parent"
	    android:layout_height="fill_parent"
	    >

	    <TextView
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:text="¾Æ·¡ÂÊÀÇ ¾ÆÀÌÄÜÀ» Ŭ¸¯/µå·¡±×Çϼ¼¿ä." />
	    
	    <SlidingDrawer 
		android:id="@+id/slide"
		android:layout_width="match_parent"
		android:layout_height="match_parent"
		android:allowSingleTap="true"
		android:animateOnClick="true"
		android:bottomOffset="5dp"
		android:content="@+id/content"
		android:handle="@+id/handle"
		android:orientation="vertical"
		android:topOffset="60dp"
		>
		<ImageView 
		    android:id="@+id/handle"
		    android:src="@drawable/ic_launcher"
		    android:layout_width="wrap_content"
		    android:layout_height="wrap_content"
		    />
		<LinearLayout 
		    android:id="@+id/content"
		    android:layout_width="match_parent"
		    android:layout_height="match_parent"
		    android:background="#FFFFFFFF"
		    android:orientation="vertical"
		    >
		    <TextView 
			android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:text="SlidingDrawerÀÇ content ºÎºÐÀÔ´Ï´Ù."
			/>
		    <Button 
			android:id="@+id/btnclose"
			android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:text="´Ý±â"
			/>
		</LinearLayout>
	    </SlidingDrawer>

	</RelativeLayout>


SlidingDrawer¸¦ Çϳª ÀÛ¼ºÇÏ¿´À¸¸ç, ±× ¾È¿¡ À̹ÌÁöºä¸¦ handle·Î ¸®´Ï¾î·¹À̾ƿôÀ» content·Î µî·ÏÇÏ¿´½À´Ï´Ù.

2. MainActivity.java ÆÄÀÏÀ» ÀÛ¼ºÇÕ´Ï´Ù.
 
	
	public class MainActivity extends Activity {
		 Button btnClose;
		 
		@Override
		public void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			setContentView(R.layout.activity_main);
				
			btnClose = (Button)findViewById(R.id.btnclose);
			btnClose.setOnClickListener(new OnClickListener() {        	
				@Override
				public void onClick(View v) {
					SlidingDrawer drawer = (SlidingDrawer)findViewById(R.id.slide);
					drawer.animateClose();
				}
			});
		}
	}
	


activity ÆÄÀÏÀº »ý°¢º¸´Ù °£´ÜÇÕ´Ï´Ù.

content ºÎºÐÀÇ ¹öÆ°¸¸À» ÂüÁ¶ÇÑ ÈÄ À̺¥Æ®¸¦ µî·ÏÇÏ°í, onClick()¸Þ¼Òµå¿¡¼­ SlidingDrawer¸¦ ÂüÁ¶ ÈÄ ´Ý´Â ±â´É¸¸À» Ãß°¡ÇÏ¿´½À´Ï´Ù.
 
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.