android 动态布局setLayoutParams方法设置

private LinearLayout generateHeadOfControl() {
	LinearLayout LayoutHead = createLayout(LinearLayout.HORIZONTAL);
    	Button DateButton = generateDateButton();
    	Button ItemButton = generateItemButton();

        DateButton.setLayoutParams(new LinearLayout.LayoutParams(100,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        ItemButton .setLayoutParams(new LinearLayout.LayoutParams(100,
                LinearLayout.LayoutParams.WRAP_CONTENT));

        layoutHead.addView(DateButton);
        layoutHead.addView(ItemButton); 

        return layoutHead;
}
==========================
注意在LinearLayout里设置params用的是ViewGroup的LayoutParams,会出错,上面的代码OK了~

你可能感兴趣的:(android,setlayoutPa)