【學習筆記】Android常用佈局


一、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


用的比較少,加進來的控件自動堆疊在一起。日後再補充

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章