Android launcher drawer class slidingdrawer!

Source: Internet
Author: User

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
  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>

 

4. SetHandleIcon style, inDrawableAddHandle. xmlThe Code is as follows:

 

[Java]
View plaincopy
  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>

 

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
  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>

 

4. SetHandleIcon style, inDrawableAddHandle. xmlThe Code is as follows:

 

[Java]
View plaincopy
  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>

 

5. Run it. The following results are displayed:

 

 

 

If you want to know more about itLauncherSource 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.