Parsing Android style: layout is fundamental

Source: Internet
Author: User

If you used to be a WEB Front-end designer, and if you used to have design skills, you are very honored. If you switch to the Android platform, both previous knowledge and experience can be well transplanted to the Android platform. I think that learning is a long-term accumulation process and experience is very important. Why do some people make money regardless of their business? Because of his experience, experience, and flexibility, he is wise.

Layout is fundamental,This is true for both WEB design and mobile client design. If the game is not deployed in the first place, even if your details are well done, you should rebuild it in the end. Compared with the layout in traditional WEB design, there are quite a few Android platforms, but the layer layout of WEB design has a new definition in Android, called frame layout. The layout is not important in this article, because it is similar to the concept in the WEB, so it takes a while.

To be honest, I still like the style naming rules in WEB design, which are simple and easy to use. The most important thing is that WEB styles are well managed. Unlike Android style files, they are not very detailed and seem messy. If you have studied the SDK design method, you will find that the style of a button is very detailed. There are more than 20 style files, such as btn_default.xml and btn_default_small.xml.

The following describes how the SDK is designed. You can customize a button style file btn_default.xml, includingNon-Focus, focus, pressedThree different statuses.

 
 
  1. 1 <?xml version="1.0" encoding="utf-8"?>    
  2.  2 <selector xmlns:android="http://schemas.android.com/apk/res/android">    
  3.  3     <item android:state_pressed="true">    
  4.  4         <shape>    
  5.  5             <gradient      
  6.  6                 android:startColor="#ff8c00"      
  7.  7                 android:endColor="#FFFFFF"    
  8.  8                 android:angle="270" />    
  9.  9      
  10. 10             <stroke      
  11. 11                 android:width="2dp"      
  12. 12                 android:color="#dcdcdc" />    
  13. 13      
  14. 14             <corners      
  15. 15                 android:radius="2dp" />    
  16. 16      
  17. 17             <padding      
  18. 18                 android:left="10dp"      
  19. 19                 android:top="10dp"    
  20. 20                 android:right="10dp"      
  21. 21                 android:bottom="10dp" />    
  22. 22      
  23. 23         </shape>    
  24. 24      
  25. 25     </item>    
  26. 26      
  27. 27     <item android:state_focused="true">    
  28. 28         <shape>    
  29. 29             <gradient      
  30. 30                 android:startColor="#ffc2b7"      
  31. 31                 android:endColor="#ffc2b7"    
  32. 32                 android:angle="270" />    
  33. 33      
  34. 34             <stroke      
  35. 35                 android:width="2dp"      
  36. 36                 android:color="#dcdcdc" />    
  37. 37      
  38. 38             <corners      
  39. 39                 android:radius="2dp" />    
  40. 40      
  41. 41             <padding    
  42. 42                 android:left="10dp"      
  43. 43                 android:top="10dp"    
  44. 44                 android:right="10dp"      
  45. 45                 android:bottom="10dp" />    
  46. 46      
  47. 47         </shape>    
  48. 48      
  49. 49     </item>    
  50. 50          
  51. 51     <item>    
  52. 52         <shape>    
  53. 53             <gradient      
  54. 54                 android:startColor="#ff9d77"      
  55. 55                 android:endColor="#ff9d77"    
  56. 56                 android:angle="270" />    
  57. 57      
  58. 58             <stroke      
  59. 59                 android:width="2dp"      
  60. 60                 android:color="#fad3cf" />    
  61. 61      
  62. 62             <corners      
  63. 63                 android:radius="2dp" />    
  64. 64      
  65. 65             <padding      
  66. 66                 android:left="10dp"      
  67. 67                 android:top="10dp"    
  68. 68                 android:right="10dp"      
  69. 69                 android:bottom="10dp" />    
  70. 70      
  71. 71         </shape>    
  72. 72      
  73. 73     </item>    
  74. 74      
  75. 75 </selector      

Selector can be understood as a state switch. Different styles are switched under different states. In traditional WEB design, it is a pseudo-class hover. Shape indicates the shape of the button.

Style reference is very simple. Android uses style files as a resource. The following describes how to use styles.

 
 
  1. 1 <Button 
  2. 2                 android:background="@drawable/btn_default" 
  3. 3                 android:layout_width="wrap_content"   
  4. 4                 android:layout_height="wrap_content" 
  5. 5                 android:text="test Style" 
  6. 6             > 
  7. 7               
  8. 8             </Button> 
  9. 9               

Effect

 

Summary

In general, Android style design is very flexible. Most concepts in WEB design are applicable to Android platforms, including style inheritance concepts.

Note: This article is copyrighted by the author. Click here to connect to the original 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.