android learn Layout_what in XML

来源:互联网 发布:虾囧笑话源码 编辑:程序博客网 时间:2024/06/05 17:19

Layout有两种方式:在XML里声明接口元素、写在代码在运行时形成。既然这两种方式都可以实现一个Layout,那么其中必然存在着某种关系。  

google的developer官网上介绍Layout部分有这样一段话:

*In general, the XML vocabulary for declaring UI elements closely follows the structure and naming of the classes and methods, where element names correspond to class names and attribute names correspond to methods. In fact, the correspondence is often so direct that you can guess what XML attribute corresponds to a class method, or guess what class corresponds to a given XML element. However, note that not all vocabulary is identical. In some cases, there are slight naming differences. For example, the EditText element has a text attribute that corresponds to EditText.setText().** 

通常情况下,声明接口元素的XML元素表紧密地继承了类和方法的结构与命名,元素的名字和类的名字对应,属性的名字与方法的名字对应。事实上,这种直接的对应关系可以让你根据XML属性猜出方法,也可以根据XML元素猜出类。但是,有一点需要明白,不是所有的元素表都是唯一的。在一些情况下,存在一些轻微的命名区别。例如,元素EditText有一个text属性,对应了EditText.setText()。 

因此,在XML中的每个元素,必然存在着一个与它对应的类;属于该元素的属性,在该类中必然存在对应的方法。并且,这种对应允许它们的名字有差别。

0 0