標籤:primary html near wrap apk rac 組件 class pad
首先要明白的是其一android中的組件使用的是盒子模型,與html標籤一樣有margin和padding屬性,但是名字不一樣。其二Android在布局中不使用px為單位,而是使用dp為長度單位,sp為字型大小單位
一、 線性布局LineaLayout
值得注意的是LinearLayout標籤有一個必要屬性android:orientation,用來指示組件是水平展開(horizontal)還是垂直展開(vertical)。下面給出一個LinearLayout的基本使用
1.水平展開--horizontal
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"><!--水平展開--> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:background="@color/colorAccent" android:text="這是文字1!" android:textSize="25sp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:background="@color/colorPrimary" android:text="這是文字2" android:textSize="20sp"/></LinearLayout>
預覽圖:可以看出第二個TextView在第一個TextView的右方
2. 垂直展開--vertical
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"><!--垂直展開--> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:background="@color/colorAccent" android:text="這是文字1!" android:textSize="25sp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:background="@color/colorPrimary" android:text="這是文字2" android:textSize="20sp"/></LinearLayout>
預覽圖:可以看出第二個TextView在第一個TextView的下方
二、
android 項目三種布局