@Override
public View initView() {
RelativeLayout container = new RelativeLayout(UIUtils.getContext());// 容器
AbsListView.LayoutParams ctparams = new AbsListView.LayoutParams(
AbsListView.LayoutParams.MATCH_PARENT, UIUtils.dip2px(150));
container.setLayoutParams(ctparams); viewPager = new ViewPager(UIUtils.getContext());// viewpager
RelativeLayout.LayoutParams vpParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
viewPager.setLayoutParams(vpParams); container.addView(viewPager);// 添加viewpager // indicator指示器的布局
llLayout = new LinearLayout(UIUtils.getContext());// 线性布局
int padding = UIUtils.dip2px(10);
llLayout.setPadding(padding, padding, padding, padding);// 设置padding值
llLayout.setOrientation(LinearLayout.HORIZONTAL);//设置水平排列
RelativeLayout.LayoutParams llParams = new RelativeLayout.LayoutParams(
// 线性布局属性
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT); llParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);// 增加线性布局规则
llParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
llLayout.setLayoutParams(llParams); ivParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT); container.addView(llLayout); // 添加指示器布局 return container;
}
LayoutParams 命名的时候,最好用与子控件相关的字符串命名,这样一看就明白了是谁的属性, 并且宽高也是子控件的宽高