android java寫佈局LinearLayou.LayoutParams參數

private LinearLayout layout;//創建一個佈局

layout = mLayout = (LinearLayout) findViewById(R.id.layout);

TextView text = new TextView(MainActivity.this);

text.setText("往layout中添加TextView");

//設置LinearLayout的參數,(寬,高)

LinearLayout.LayoutParams p = 

new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);

layout.addView(text,p);//往layout中添加TextView

發佈了19 篇原創文章 · 獲贊 2 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章