View plaincopy to clipboardprint?
- <? 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>
- This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/Android_Tutor/archive/2010/04/14/5486804.aspx
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <selector xmlns: Android = "http://schemas.android.com/apk/res/android"> <br/> <item Android: state_window_focused = "false" Android: state_enabled = "true" Android: drawable = "@ drawable/handle_normal"/> <br/> <item Android: state_pressed = "true" Android: drawable = "@ drawable/handle_pressed"/> <br/> <item Android: state_focused = "true" Android: state_enabled = "true" Android: drawable = "@ drawable/handle_focused"/> <br/> <item Android: state_enabled = "true" Android: drawable = "@ drawable/handle_normal"/> <br/> <item Android: state_focused = "true" Android: drawable = "@ drawable/handle_focused"/> <br/> </selector> </P> <p> This article is from the csdn blog, reprinted please indicate the source: http://blog.csdn.net/Android_Tutor/archive/2010/04/14/5486804.aspxI recently studied lanucher, read the source code, and found the slidingdrawer class, which is also called the "drawer" class. It is easy to use, including handle, and content.
Handle is when you click it, the content is either drawer or close the drawer. The specific steps are as follows.
1. Create an android project named slidingdrawer.
2. Prepare materials. Here, my icons use the icons in launcher2 and put them in the drawable-hdpi folder. The directory structure is as follows:
3. Set the main. xml layout: the code is as follows:
View plaincopy to clipboardprint?
- <? 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>
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "vertical" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> Android: background = "#808080" <br/> <sshortingdrawer <br/> Android: Id = "@ + ID/sshortingdrawer" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> Android: Orientation = "vertical" <br/> Android: handle = "@ + ID/handle" <br/> Android: content = "@ + ID/content"> <br/> <button <br/> Android: id = "@ + ID/handle" <br/> Android: layout_width = "88dip" <br/> Android: layout_height = "44dip" <br/> Android: background = "@ drawable/handle" <br/> <linearlayout <br/> Android: id = "@ + ID/content" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> Android: background = "#00ff00"> <br/> <button <br/> Android: Id = "@ + ID/button" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "button" <br/> <edittext <br/> Android: Id = "@ + ID/edittext" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> </linearlayout> <br/> </slidingdrawer> <br/> </linearlayout>
4. Set the handle icon style and add handle. XML to drawable. The Code is as follows:
View plaincopy to clipboardprint?
- <? 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>
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <selector xmlns: Android = "http://schemas.android.com/apk/res/android"> <br/> <item Android: state_window_focused = "false" Android: state_enabled = "true" Android: drawable = "@ drawable/handle_normal"/> <br/> <item Android: state_pressed = "true" Android: drawable = "@ drawable/handle_pressed"/> <br/> <item Android: state_focused = "true" Android: state_enabled = "true" Android: drawable = "@ drawable/handle_focused"/> <br/> <item Android: state_enabled = "true" Android: drawable = "@ drawable/handle_normal"/> <br/> <item Android: state_focused = "true" Android: drawable = "@ drawable/handle_focused"/> <br/> </selector>
5. Run it. The following results are displayed:
It's relatively simple. If you want to know more about it, let's look at the launcher source code!