XML Syntax
如同英文有文法(grammar),像是第三人稱動詞要加 s ; 程式語言也有語法需要遵循,這樣寫出來的程式才能運行。我們從 XML 的語法開始學習,下面是一個 TextView 的 XML element。開頭與結尾都會有尖括號,開頭的尖括號後面是 view name,每一行我們可以拆成 attribute name 與 attribute value,後面的 value 要有引號(quotation)。
- Syntax means the rules that define what valid XML is.
- Start with an opening angle bracket, followed by the view name.
- View name like TextView, ImageView, button.
- In the end of the block, we have a forward slash and a closing angle bracket.
- For every XML element, when you start or open up a tag, you always need to close it. It is called self-closing tag.
至於尖括號的使用,上面的案例是一個 self-closing tag,下面而是用 separate opening tag 跟 separate closing tag。opening 跟 closing 的差別是斜槓(forward slash),closing tag 有 slash
到 1:36:https://classroom.udacity.com/courses/ud834/lessons/4027328704/concepts/42555185990923
- We have a list of attributes here one per line.
- attribute 就像一個人的特徵,black hair, brown eye
- All attribute 都有default value,你沒寫就是 default
- 像第二行 background 的 default 是 transparent