[안드로이드] Resources Naming Rule

같은 프로젝트를 오랫동안 개발하다 보면 drawable이나 layout 같은 리소스명이 규칙 없이 생성되게 된다. 여러 사람이 개발하거나, 내 마음이 바뀌거나... 리소스 작명 규칙을 정해놓고 그 규칙을 따르다 보면 가독성이 높아진다.

Basic Principle

[what]_[where]_[description]_[size]
  • what activity, fragment ...
  • where main, user, settings ...
  • description title, content, profile ...
  • size 24dp, small ... (optional)

Layout

[what]_[where].xml
  • activity, fragment, view , item, layout
  • 예시 activity_main.xml, layout_article.xml

Strings

[where]_[description]
  • 공통적인 문자열은 [where]all 또는 common을 사용
  • 예시 article_title, common_purchase

Drawables

[where]_[description]_[size]
  • 공통 이미지는 all, common을 사용
  • 예시 noti_icon_24dp

Ids

[what]_[where]_[description]
  • 예시 tablayout_main, imageview_menu_profile

Dimensions

[what]_[where]_[description]_[size]
  • waht은 width, height, size, margin, padding같은 것들이 들어갈 수 있다.
  • 예시 height_toolbar, size_profile

한계점

  • 모든 화면이 다른 이름을 가져야함 (MainActivity, MainFragment는 같은 main을 사용하기 때문에 충돌이 일어날수 있음)
  • 리펙토링이 자동으로 되지는 않음

출처: http://jeroenmols.com/blog/2016/03/07/resourcenaming/

Juyeong Lee

구직중입니다. https://www.linkedin.com/in/juyeong/