Android advanced tutorial (II)-How to Use Android launcher drawer class slidingdrawer!

Source: Internet
Author: User
View plaincopy to clipboardprint?
  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Selector xmlns: Android = "http://schemas.android.com/apk/res/android">
  3. <Item Android: state_window_focused = "false" Android: state_enabled = "true" Android: drawable = "@ drawable/handle_normal"/>
  4. <Item Android: state_pressed = "true" Android: drawable = "@ drawable/handle_pressed"/>
  5. <Item Android: state_focused = "true" Android: state_enabled = "true" Android: drawable = "@ drawable/handle_focused"/>
  6. <Item Android: state_enabled = "true" Android: drawable = "@ drawable/handle_normal"/>
  7. <Item Android: state_focused = "true" Android: drawable = "@ drawable/handle_focused"/>
  8. </Selector>
  9. 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?
  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
  3. Android: Orientation = "vertical"
  4. Android: layout_width = "fill_parent"
  5. Android: layout_height = "fill_parent"
  6. Android: Background = "#808080"
  7. >
  8. <Slidingdrawer
  9. Android: Id = "@ + ID/slidingdrawer"
  10. Android: layout_width = "fill_parent"
  11. Android: layout_height = "fill_parent"
  12. Android: Orientation = "vertical"
  13. Android: handle = "@ + ID/handle"
  14. Android: content = "@ + ID/content">
  15. <Button
  16. Android: Id = "@ + ID/handle"
  17. Android: layout_width = "88dip"
  18. Android: layout_height = "44dip"
  19. Android: Background = "@ drawable/handle"
  20. />
  21. <Linearlayout
  22. Android: Id = "@ + ID/content"
  23. Android: layout_width = "fill_parent"
  24. Android: layout_height = "fill_parent"
  25. Android: Background = "#00ff00">
  26. <Button
  27. Android: Id = "@ + ID/button"
  28. Android: layout_width = "wrap_content"
  29. Android: layout_height = "wrap_content"
  30. Android: text = "button"
  31. />
  32. <Edittext
  33. Android: Id = "@ + ID/edittext"
  34. Android: layout_width = "fill_parent"
  35. Android: layout_height = "wrap_content"
  36. />
  37. </Linearlayout>
  38. </Slidingdrawer>
  39. </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?
  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Selector xmlns: Android = "http://schemas.android.com/apk/res/android">
  3. <Item Android: state_window_focused = "false" Android: state_enabled = "true" Android: drawable = "@ drawable/handle_normal"/>
  4. <Item Android: state_pressed = "true" Android: drawable = "@ drawable/handle_pressed"/>
  5. <Item Android: state_focused = "true" Android: state_enabled = "true" Android: drawable = "@ drawable/handle_focused"/>
  6. <Item Android: state_enabled = "true" Android: drawable = "@ drawable/handle_normal"/>
  7. <Item Android: state_focused = "true" Android: drawable = "@ drawable/handle_focused"/>
  8. </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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.