之前报名了Google举办的Study Jams,现在已经成功结业了,也勉强算是入门了Android。
VIEW
XML,可拓展标记语言。
在Android中,使用XML来确定不同的VIEWS。
XML中由一个个不同的标签构成,需要注意每个标签结束之后都要关闭标签。如:/>或</LinearLayout>
标签中有各种不同的属性。属性可以决定手机上View的行为或外观的特性。
View的分类
常见的VIEW:
- TextView
- ImageView
- Button
- ScrollView
dp
dp (density-independent pixles) 密度无关像素
wrap_content
自适应宽度或高度
设置字体大小
android:textSize=”45sp”
android:textAppearance=”?android:textAppearanceLarge”
设置字体颜色
android:textColor=”@andorid:color/darker_gray”
android:textColor=”#十六进制数”
具体配色可在Materal Design上查看
ImageView
@drawable/cake
只引用有效文件
@:引用
drawable:引用类型
cake:文件名(不需要后缀)
ViewGroup
match_parent
将当前View设置成与父视图等宽或等高
子视图空间平分
|
|
View边框
padding
包含边框
- andorid:padding = “8dp”
OR - andorid:paddingLeft = “8dp”
- andorid:paddingRight = “8dp”
- andorid:paddingTop = “8dp”
- andorid:paddingBottom = “8dp”
margin
不包含边框
- andorid:layout_margin = “8dp”
OR - andorid:layout_marginLeft = “8dp”
- andorid:layout_marginRight = “8dp”
- andorid:layout_marginTop = “8dp”
- andorid:layout_marginBottom = “8dp”
LinearLayout例子:1234567891011121314151617181920212223242526<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><ImageViewandroid:src="@drawable/ocean"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:scaleType="centerCrop" /><TextViewandroid:text="You're invited!"android:layout_width="match_parent"android:layout_height="wrap_content"android:textColor="@android:color/white"android:textSize="54sp"android:background="#009688" /><TextViewandroid:text="Bonfire at the beach"android:layout_width="match_parent"android:layout_height="wrap_content"android:textColor="@android:color/white"android:textSize="34sp"android:background="#009688" /></LinearLayout>

RelativeLayout
- 可以将子视图与父布局或子视图之间相对排列
View在父视图中摆放位置
- android:layout_alignParentTop = “true” or “false”
- android:layout_alignParentBottom = “true” or “false”
- android:layout_alignParentLeft = “true” or “false”
- android:layout_alignParentRight = “true” or “false”
- android:layout_centerHorizontal = “true” or “false”
- android:layout_centerVertical = “true” or “false”
View之间的相对摆放位置
- android:id = “@id+/id_name”
- android:layout_toLeftOf = “@id/id_name”
- android:layout_above = “@id/id_name”


