简体   繁体   English

R.id.myView 指的是什么?

[英]What does R.id.myView refer to?

你能告诉我这个名字的三个单一组成部分指的是什么吗?

R.id.myView

R - R.java is an auto-generated file by aapt (Android Asset Packaging Tool) which contains resource IDs for all the resources of res directory. R - R.java 是由 aapt(Android 资产打包工具)自动生成的文件,其中包含 res 目录下所有资源的资源 ID。

public final class R 
extends Object 

.id - Find view using its id "defined by you" .id - 使用其“由您定义”的 id 查找视图

public static final class R.id 
extends Object 

myView - It is the view that you defined using the android:id="@+id/your_view" attribute in your XML file. myView - 这是您在 XML 文件中使用android:id="@+id/your_view"属性定义的视图。

So, finally we can find or identify any view using R.id.your_view.所以,最后我们可以使用 R.id.your_view 找到或识别任何视图。

android.R -R is a final public class in android. android.R -R 是 android 中的最终公共类。 It extends Object class and it has many nested classes like R.id , R.anim , etc.它扩展了 Object 类,并且它有许多嵌套类,如R.idR.anim等。

R.java is Automatically System generated file and contains the id of each resources used in the Application which is used to make reference. R.java是系统自动生成的文件,包含应用程序中使用的每个资源的 id,用于参考。 R.class contains IDs for all your android resources. R.class 包含所有 android 资源的 ID。

android.R.id is a nested class of R class. android.R.id是 R 类的嵌套类。 It has many static final constants like text1 , toggle , button , etc.它有许多静态最终常量,如text1togglebutton等。

android.R.id.myView is an identifier of a View class. android.R.id.myView是一个 View 类的标识符。 It represents an id for corresponding view defined in XML.它代表在 XML 中定义的相应视图的 id。

Android R.java is an auto-generated file by aapt (Android Asset Packaging Tool) that contains resource IDs for all the resources of res/ directory. Android R.java是由aapt (Android Asset Packaging Tool)自动生成的文件,其中包含 res/ 目录下所有资源的resource IDs

Whenever you use any recourse in you project then its one Unique Id will be generated automatically and you can identify that resource by using that id.每当您在项目中使用任何资源时,都会自动生成其唯一 ID,您可以使用该 ID 识别该资源。 You can not delete this file.您无法删除此文件。

R :- Java class is collection of your all resources with its related id. R :- Java 类是您的所有资源及其相关 ID 的集合。

id :- Whenever you create any resource and assign the id by using @+id then R file create one unique id for that resource. id :- 每当您创建任何资源并使用@+id分配 id 时, R文件都会为该资源创建一个唯一的 id。

myView :- Its view id name that user can identify and By using that view id name we can identify that view in activity java file. myView :- 用户可以识别的视图 ID 名称,通过使用该视图 ID 名称,我们可以在活动 java 文件中识别该视图。

Below are the example of view id's in R.java file.下面是R.java文件中视图 ID 的示例。 If you want to show that where it is located then check this answer.如果您想显示它的位置,请查看此答案。

Example of R.Java file R.Java 文件示例

public final class R {  
    public static final class attr {  
    }  
    public static final class drawable {  
        public static final int ic_launcher=0x7f020000;  
    }  
    public static final class id {  
        public static final int menu_settings=0x7f070000;  
    }  
    public static final class layout {  
        public static final int activity_main=0x7f030000;  
    }  
    public static final class menu {  
        public static final int activity_main=0x7f060000;  
    }  
    public static final class string {  
        public static final int app_name=0x7f040000;  
        public static final int hello_world=0x7f040001;  
        public static final int menu_settings=0x7f040002;  
    }  
    public static final class style {  

        public static final int AppBaseTheme=0x7f050000;  
        public static final int AppTheme=0x7f050001;  
    }  
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM