2020 0208 setContentView
setContentView
原文
android.support.v7.app.AppCompatActivity public void setContentView(@LayoutRes int layoutResID)
Description copied from class: android.app.Activity
Set the activity content from a layout resource. The resource will be inflated, adding all top-level views to the activity.
Overrides: setContentView in class Activity
Params: layoutResID – Resource ID to be inflated.
总译
描述复制自类android.app.Activity。
设置布局资源中的活动内容。
传入的资源将会被填充,所有顶级视图都会加入到活动中。
重写:Activity类中的setContentView。
参数:layoutResID——用于填充的资源的ID。
findViewById
原文
android.support.v7.app.AppCompatActivity public <T extends android.view.View> T findViewById(@IdRes int id)
Description copied from class: android.app.Activity
Finds a view that was identified by the android:id XML attribute that was processed in onCreate.
Note: In most cases – depending on compiler support – the resulting view is automatically cast to the target class type. If the target class type is unconstrained, an explicit cast may be necessary.
Overrides: findViewById in class Activity
Params: id – the ID to search for
Returns: a view with given ID if found, or null otherwise.
总译
描述复制自类android.app.Activity。
查找要在onCreate方法中处理的视图,该视图由xml文件中android:id这一属性进行标识。
注意:在大多数情况下(取决于编译器的支持),查找到的结果视图类型会被强制转化为目标类类型,如果目标类类型是无约束的,那么可能需要进行显式强制转换。
重写:Activity类中的findViewById。
参数:id——要查找的视图的id。
返回:若找到则返回该id对应的视图,否则返回null。
findViewById官方文档链接
积累
cast to
强制转换,强制转化
cast
v. 浇铸;投;抛
compiler
n. 编译器;编译程序
参考学习自:
Android Studio 里的源码解释文档(鼠标划至相应代码自动调取英文释义)
另:
setContentView官方文档链接
findViewById官方文档链接
此文仅交流学习,与诸君共勉进步!
如有不当之处,望告知以便改进。