Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

android - Are there conventions on how to name resources?

Are there conventions how to name resources in Android? For example, buttons, textViews, menus, etc.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Android SDK will be a good place to start.

For example, I try to scope IDs within the activity.

If I had a ListView it simply would be @android:id/list in all the activities.
If, however, I had two lists then I would use the more specific @id/list_apple and @id/list_orange

So generic (ids, ...) gets reused in the R.java file while the unique ones (sometimes gets reused) get prefixed with generic ones separated by an underscore.


The underscore is one thing, I observed, for example:

Layout width is layout_width in xml and layoutWidth in code, so I try to stick to it as list_apple

So a Login button will be login, but if we have two logins then login_foo and login_bar.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...