當分配一個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