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了~
第二篇

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM