From: http://blog.csdn.net/android_tutor/article/details/5486804
Recent studiesLanucher, Read the source code, and foundSlidingdrawerThis class is also called the "drawer" class. It is easy to use, includingHandle, AndContent.
HandleWhen you click it,ContentEither drawer or close drawer. The specific steps are as follows.
1. CreateAndroidProject, namedSlidingdrawer.
2. Prepare materials. Here my icons are usedLauncher2Put the icon inDrawable-hdpiThe folder directory structure is as follows:
3. SetMain. xmlLayout: the code is as follows:
[Java]
View plaincopy
- <? XML version = "1.0" encoding = "UTF-8"?>
- <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
- Android: Orientation = "vertical"
- Android: layout_width = "fill_parent"
- Android: layout_height = "fill_parent"
- Android: Background = "#808080"
- >
- <Slidingdrawer
- Android: Id = "@ + ID/slidingdrawer"
- Android: layout_width = "fill_parent"
- Android: layout_height = "fill_parent"
- Android: Orientation = "vertical"
- Android: handle = "@ + ID/handle"
- Android: content = "@ + ID/content">
- <Button
- Android: Id = "@ + ID/handle"
- Android: layout_width = "88dip"
- Android: layout_height = "44dip"
- Android: Background = "@ drawable/handle"
- />
- <Linearlayout
- Android: Id = "@ + ID/content"
- Android: layout_width = "fill_parent"
- Android: layout_height = "fill_parent"
- Android: Background = "#00ff00">
- <Button
- Android: Id = "@ + ID/button"
- Android: layout_width = "wrap_content"
- Android: layout_height = "wrap_content"
- Android: text = "button"
- />
- <Edittext
- Android: Id = "@ + ID/edittext"
- Android: layout_width = "fill_parent"
- Android: layout_height = "wrap_content"
- />
- </Linearlayout>
- </Slidingdrawer>
- </Linearlayout>
4. SetHandleIcon style, inDrawableAddHandle. xmlThe Code is as follows:
[Java]
View plaincopy
- <? XML version = "1.0" encoding = "UTF-8"?>
- <Selector xmlns: Android = "http://schemas.android.com/apk/res/android">
- <Item Android: state_window_focused = "false" Android: state_enabled = "true" Android: drawable = "@ drawable/handle_normal"/>
- <Item Android: state_pressed = "true" Android: drawable = "@ drawable/handle_pressed"/>
- <Item Android: state_focused = "true" Android: state_enabled = "true" Android: drawable = "@ drawable/handle_focused"/>
- <Item Android: state_enabled = "true" Android: drawable = "@ drawable/handle_normal"/>
- <Item Android: state_focused = "true" Android: drawable = "@ drawable/handle_focused"/>
- </Selector>
5. Run it. The following results are displayed:
If you want to know more about itLauncherSource code!
Recent studiesLanucher, Read the source code, and foundSlidingdrawerThis class is also called the "drawer" class. It is easy to use, includingHandle, AndContent.
HandleWhen you click it,ContentEither drawer or close drawer. The specific steps are as follows.
1. CreateAndroidProject, namedSlidingdrawer.
2. Prepare materials. Here my icons are usedLauncher2Put the icon inDrawable-hdpiThe folder directory structure is as follows:
3. SetMain. xmlLayout: the code is as follows:
[Java]
View plaincopy
- <? XML version = "1.0" encoding = "UTF-8"?>
- <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
- Android: Orientation = "vertical"
- Android: layout_width = "fill_parent"
- Android: layout_height = "fill_parent"
- Android: Background = "#808080"
- >
- <Slidingdrawer
- Android: Id = "@ + ID/slidingdrawer"
- Android: layout_width = "fill_parent"
- Android: layout_height = "fill_parent"
- Android: Orientation = "vertical"
- Android: handle = "@ + ID/handle"
- Android: content = "@ + ID/content">
- <Button
- Android: Id = "@ + ID/handle"
- Android: layout_width = "88dip"
- Android: layout_height = "44dip"
- Android: Background = "@ drawable/handle"
- />
- <Linearlayout
- Android: Id = "@ + ID/content"
- Android: layout_width = "fill_parent"
- Android: layout_height = "fill_parent"
- Android: Background = "#00ff00">
- <Button
- Android: Id = "@ + ID/button"
- Android: layout_width = "wrap_content"
- Android: layout_height = "wrap_content"
- Android: text = "button"
- />
- <Edittext
- Android: Id = "@ + ID/edittext"
- Android: layout_width = "fill_parent"
- Android: layout_height = "wrap_content"
- />
- </Linearlayout>
- </Slidingdrawer>
- </Linearlayout>
4. SetHandleIcon style, inDrawableAddHandle. xmlThe Code is as follows:
[Java]
View plaincopy
- <? XML version = "1.0" encoding = "UTF-8"?>
- <Selector xmlns: Android = "http://schemas.android.com/apk/res/android">
- <Item Android: state_window_focused = "false" Android: state_enabled = "true" Android: drawable = "@ drawable/handle_normal"/>
- <Item Android: state_pressed = "true" Android: drawable = "@ drawable/handle_pressed"/>
- <Item Android: state_focused = "true" Android: state_enabled = "true" Android: drawable = "@ drawable/handle_focused"/>
- <Item Android: state_enabled = "true" Android: drawable = "@ drawable/handle_normal"/>
- <Item Android: state_focused = "true" Android: drawable = "@ drawable/handle_focused"/>
- </Selector>
5. Run it. The following results are displayed:
If you want to know more about itLauncherSource code!