이 튜토리얼에서는 안드로이드에서 SlidingDrawer가 기본 설정인 아래 방향이 아니라 화면 왼쪽에서 슬라이드되어 열리도록 구현하는 방법을 단계별로 살펴봅니다.
핵심 원리는 간단합니다. SlidingDrawer 자체와 내부 콘텐츠에 android:rotation="180" 속성을 적용하고, 핸들(손잡이) 이미지에는 android:rotation="270"을 적용하면 드로어의 방향이 회전되어 왼쪽에서 밀려 나오는 형태로 동작하게 됩니다.
참고: SlidingDrawer는 API 17(안드로이드 4.2)부터 공식적으로 지원 중단(deprecated)되었습니다. 최신 앱 개발에서는 DrawerLayout이나 BottomSheet 사용을 권장하지만, 레거시 프로젝트 유지보수나 학습 목적이라면 아래 방법이 여전히 유용합니다.
1단계 — 새 프로젝트 생성
Android Studio에서 File → New Project 메뉴로 이동한 뒤, 필요한 정보를 모두 입력하여 새 프로젝트를 생성합니다.
2단계 — 레이아웃 파일 작성
res/layout/activity_main.xml 파일에 아래 코드를 추가합니다.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="https://schemas.android.com/apk/res/android" xmlns:tools="https://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="4dp" tools:context=".MainActivity"> <SlidingDrawer android:id="@+id/slidingDrawer" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:handle="@id/handler" android:rotation="180" android:content="@+id/content"> <ImageView android:id="@+id/handler" android:layout_width="100dp" android:layout_height="100dp" android:src="@drawable/ic_arrow_upward_black_24dp" android:rotation="270" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:rotation="180" android:id="@+id/content" android:orientation="horizontal"> <ImageView android:id="@+id/imageView1" android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/image" /> </LinearLayout> </SlidingDrawer> </LinearLayout>
코드 설명
- android:rotation="180" — SlidingDrawer 전체를 180도 회전시켜 열리는 방향을 반대로 뒤집습니다.
- android:handle / android:content — 각각 드로어의 손잡이와 펼쳐질 콘텐츠 영역을 지정합니다.
- 핸들 ImageView의 rotation="270"은 화살표 아이콘이 왼쪽을 가리키도록 조정하는 역할을 합니다.
3단계 — MainActivity.java 작성
src/MainActivity.java 파일에 아래 코드를 추가합니다. 이 예제에서는 별도의 로직 없이 레이아웃만 연결하면 됩니다.
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}4단계 — AndroidManifest.xml 확인
androidManifest.xml 파일에 아래와 같이 메인 액티비티가 등록되어 있는지 확인합니다.
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="https://schemas.android.com/apk/res/android" package="app.com.sample"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
앱 실행 및 결과 확인
이제 애플리케이션을 실행해 보겠습니다. 실제 안드로이드 기기가 컴퓨터에 연결되어 있다고 가정합니다. Android Studio에서 프로젝트의 액티비티 파일 중 하나를 연 뒤, 상단 툴바의 Run
아이콘을 클릭합니다. 실행할 모바일 기기를 선택하면, 기기 화면에 아래와 같은 결과가 표시됩니다.

핸들을 왼쪽으로 드래그하면 드로어가 부드럽게 펼쳐지며 내부에 설정된 이미지 콘텐츠가 나타나는 것을 확인할 수 있습니다. 이처럼 rotation 속성만 잘 활용하면 기본 SlidingDrawer의 방향을 자유롭게 변경할 수 있습니다.