标签:
1 @Override 2 public View initView() { 3 RelativeLayout container = new RelativeLayout(UIUtils.getContext());// 容器 4 AbsListView.LayoutParams ctparams = new AbsListView.LayoutParams( 5 AbsListView.LayoutParams.MATCH_PARENT, UIUtils.dip2px(150)); 6 container.setLayoutParams(ctparams); 7 8 viewPager = new ViewPager(UIUtils.getContext());// viewpager 9 RelativeLayout.LayoutParams vpParams = new RelativeLayout.LayoutParams( 10 RelativeLayout.LayoutParams.MATCH_PARENT, 11 RelativeLayout.LayoutParams.MATCH_PARENT); 12 viewPager.setLayoutParams(vpParams); 13 14 container.addView(viewPager);// 添加viewpager 15 16 // indicator指示器的布局 17 llLayout = new LinearLayout(UIUtils.getContext());// 线性布局 18 int padding = UIUtils.dip2px(10); 19 llLayout.setPadding(padding, padding, padding, padding);// 设置padding值 20 llLayout.setOrientation(LinearLayout.HORIZONTAL);//设置水平排列 21 RelativeLayout.LayoutParams llParams = new RelativeLayout.LayoutParams( 22 // 线性布局属性 23 RelativeLayout.LayoutParams.WRAP_CONTENT, 24 RelativeLayout.LayoutParams.WRAP_CONTENT); 25 26 llParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);// 增加线性布局规则 27 llParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 28 llLayout.setLayoutParams(llParams); 29 30 ivParams = new LinearLayout.LayoutParams( 31 LinearLayout.LayoutParams.WRAP_CONTENT, 32 LinearLayout.LayoutParams.WRAP_CONTENT); 33 34 container.addView(llLayout); // 添加指示器布局 35 36 return container; 37 }
LayoutParams 命名的时候,最好用与子控件相关的字符串命名,这样一看就明白了是谁的属性, 并且宽高也是子控件的宽高
LayoutParams 命名的时候,最好用与子控件相关的字符串命名,
标签:
原文地址:http://www.cnblogs.com/johnsonwei/p/5672142.html