一、LinearLayout線性佈局
(1)線性佈局分爲垂直和水平兩個方向
android:orientation="vertical" android:orientation="horizontal"
(2)定義寬和高
鋪滿父級容器:match_parent 根據內容自適應:wrap_content
android:layout_width="" android:layout_height=""
(3)設置權重
android:layout_weight="1" 全部
二、RelativityLayout相對佈局
//新建並設置一個RelativityLayout佈局
RelativityLayout root=new RelativityLayout(this);
setContentView(root);
//添加一個textView控件
TextView tv=new TextView(this);
tv.setText("hello");
//定義RelativityLayout參數,有兩個參數高和寬
RelativityLayout.LayoutParams lp=new RelativityLayout.LayoutParams(RelativityLayout.LayoutParams.WrapContent,RelativityLayout.LayoutParams.WrapContent);
root.addView(tv,lp);
三、 FrameLayout
用的比較少,加進來的控件自動堆疊在一起。日後再補充