Android 布局内视图的全局或局部id?
为xml资源中的布局视图分配id时,我通常会执行以下操作: (示例) 联系www.info.xmlAndroid 布局内视图的全局或局部id?,android,android-layout,Android,Android Layout,为xml资源中的布局视图分配id时,我通常会执行以下操作: (示例) 联系www.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
<?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更好,还是只使用“名称”就足够了?正如我指出的Hardik4560,最好使用足够描述性且不太长的名称 认识到您的应用程序可能会增长很多(谁知道呢!?),可能会有一天,您不再知道每个标识符属于哪个布局
问候 合适的约定如下: 根据您提供的示例,文本视图的适当id为:
contactinfo\u textview\u name
请注意,这不是规则。你可以使用任何你觉得舒服的东西!干杯这完全取决于有多少元素,以及你是否要引用它。最好给任何视图命名,使其不言自明。为此,你可以使用txt_contact_info_name,这将告诉我它是一个文本视图。通过使用这样的前缀,您将了解视图的类型