当分配一个ID在一个XML资源布局的观点,我通常会做这样的事情:布局中视图的全局或本地ID?
(例如) contact_info.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/contact_info_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
这里TextView中包含的名称联系。 使用这样一个完整的id更好还是只是“名称”就够了?
这完全取决于有多少元素以及是否要引用它。 – DeeV 2012-04-26 14:16:52
它总是更好地命名任何视图,以便它是自我解释。 为此你可以使用txt_contact_info_name,它会告诉我它的文本视图。通过使用这些前缀,您将了解视图的类型 – Hardik4560 2012-04-26 14:20:43