码迷,mamicode.com
首页 > 移动开发 > 详细

android编程中setLayoutParams方法设置

时间:2015-05-23 11:16:44      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

第一篇
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

android编程中setLayoutParams方法设置

标签:

原文地址:http://www.cnblogs.com/exmyth/p/4523820.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!