1. Pay attention to the id format. For example, the ID of ListView is lv_xxx, and the ID of TextView is tv_xxx. 2. Pay attention to the meaning of ID. Don't write an ID that is too long, just keep it simple and intuitive, for example: Forum page > Post details > Title TextView. There is no need to write it as tv_forum_post_title, just write it as tv_title 3. Reduce nesting. If you can use FrameLayout, don't use LinearLayout. As for RelativeLayout. . . Personally, I think it should be used as little as possible, as it will generate a bunch of meaningless IDs. . . 4. Reusing layouts is useless in most cases. It is better to extract it directly into a custom view. Write a few properties. This makes it easier to reuse.
Ui reuse probability is very low. Common dialog listview actionbar and the like are written in Java, and other codes are extracted depending on the situation. Personal suggestion: Try not to reuse UI except for basic controls. Data coupling is too high
In addition, starting from Android Studio 2.2 preview, ConstraintLayout layout was introduced to handle the mutual relationship between components through constraints. In the future, the operation of ui components will become more visual. The adjustment cost of UI is reduced, and the reuse rate of UI is low. Personally, I feel that it does not make much sense to spend a lot of effort to create a reusable layout. In actual development, only simple components are often extracted, such as search bar, bottom bar, login box, etc. For complex UI, it is often only necessary to comply with some simple specifications. As mentioned above, short and expressive names, unified style, etc.
1. The main layout file only contains include
2. Naming convention
3. Unified style
4. Don’t overly complicate the nesting level
1. Pay attention to the id format. For example, the ID of ListView is lv_xxx, and the ID of TextView is tv_xxx.
2. Pay attention to the meaning of ID. Don't write an ID that is too long, just keep it simple and intuitive, for example: Forum page > Post details > Title TextView. There is no need to write it as tv_forum_post_title, just write it as tv_title
3. Reduce nesting. If you can use FrameLayout, don't use LinearLayout. As for RelativeLayout. . . Personally, I think it should be used as little as possible, as it will generate a bunch of meaningless IDs. . .
4. Reusing layouts is useless in most cases. It is better to extract it directly into a custom view. Write a few properties. This makes it easier to reuse.
Ui reuse probability is very low. Common dialog listview actionbar and the like are written in Java, and other codes are extracted depending on the situation. Personal suggestion: Try not to reuse UI except for basic controls. Data coupling is too high
In addition, starting from Android Studio 2.2 preview, ConstraintLayout layout was introduced to handle the mutual relationship between components through constraints. In the future, the operation of ui components will become more visual. The adjustment cost of UI is reduced, and the reuse rate of UI is low. Personally, I feel that it does not make much sense to spend a lot of effort to create a reusable layout.
In actual development, only simple components are often extracted, such as search bar, bottom bar, login box, etc. For complex UI, it is often only necessary to comply with some simple specifications. As mentioned above, short and expressive names, unified style, etc.