search

Home  >  Q&A  >  body text

android布局想要有益于后期维护应该注意什么

比如布局重用之类

PHP中文网PHP中文网2810 days ago568

reply all(4)I'll reply

  • 阿神

    阿神2017-04-17 17:34:55

    1. The main layout file only contains include
    2. Naming convention
    3. Unified style
    4. Don’t overly complicate the nesting level

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:34:55

    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.

    reply
    0
  • 迷茫

    迷茫2017-04-17 17:34:55

    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

    reply
    0
  • 黄舟

    黄舟2017-04-17 17:34:55

    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.

    reply
    0
  • Cancelreply