Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Android XML Naming Convention

NotificationsYou must be signed in to change notification settings

orioonyx/XML-Naming-Convention

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 

Repository files navigation

Android uses XML to define the layout of its user interface elements. The structure and naming of XML elements are important in ensuring that the user interface is well-defined, easy to understand, and maintainable.

Here are some general naming conventions for Android XML files:

Basic Principle

<WHAT>-<WHERE>-<DESCRIPTION>-<SIZE>

WHAT

Indicate what the resource actually represents, often a standard Android view class. Limited options per resource type.

ex) activity, fragment, view, item, layout...

WHERE

Describe where it logically belongs in the app. Resources used in multiple screens use all, all others use the custom part of the Android view subclass they are in.

ex) all, main, home, login, user...

DESCRIPTION

Differentiate multiple elements in one screen.

ex) title, content, info, profile...

SIZE (optional)

Either a precise size or size bucket. Optionally used for drawables and dimensions.

ex) 24dp, small...


Layouts

<WHAT>_<WHERE>_<DESCRIPTION>.xml

ex) activity_main.xml, fragment_onboarding, item_product, fragment_product_search

Strings

<WHERE>_<DESCRIPTION> or all_<DESCRIPTION>

ex) main_title, user_namehint, login_titlehint, all_done, all_fail

Drawables

<WHAT>_<WHERE>_<DESCRIPTION>_<SUFFIX><SUFFIX> : <DIRECTION>_<SHAPE>_<OUTLINE>_<STATE>_<COLOR>_<SIZE>

WHAT : ic, bg, img, logo...
WHERE : navi, tab, home, login...
DESCRIPTION : check, like, btn, close...

SUFFIX :

DIRECTION : left, right, up, down...
SHAPE : circle, square, roundsquare...
OUTLINE : outline, border...
STATE : on, off, activated, disabled, normal...
COLOR : white, black...
SIZE : 24dp, small...

ex) ic_login_btn_disabled.png, ic_heart_on.png, ic_check_white_small.png

IDs

<KIND>_<WHERE>

KIND :

(most commonly used android view classes)

View ClassAbbrevation
CoordinatorLayoutcdl
ConstraintLayoutcsl
LinearLayoutll
RelativeLayoutrl
AppBarLayoutabl
Buttonbtn
EditTextet
TextViewtv
ProgressBarpb
Checkboxchk
RadioButtonrb
ToggleButtontb
Spinnerspn
Menumnu
ListViewlv
RecyclerViewrv
GalleryViewgv

ex) iv_profile, et_login_username, btn_submit, rv_product

Dimensions

<WHAT>_<WHERE>_<DESCRIPTION>_<SIZE>

WHAT :

PrefixUsage
widthwidth in dp
heightheight in dp
sizeif width == height
marginmargin in dp
paddingpadding in dp
elevationelevation in dp
keylineabsolute keyline measured from view edge in dp
textsizesize of text in sp

ex) height_toolbar, textsize_nomal


[8]ページ先頭

©2009-2025 Movatter.jp