第一篇
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了~
第二篇
textView.setLayoutParams(new TextSwitcher.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
为什么要用TextSwitcher的LayoutParams呢。查一查API,可以看到这么一句话These supply parameters to the parent of this view specifying how it should be arranged。也就是说一定要用父控件的LayoutParams。如果父控件是LinearLayout,当然就必须写成LinearLayout.LayoutParams