1,LinnerLayout布局的创建和属性设置,并往里面添加子控件。
linearLayout = new LinearLayout(context);
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
linearLayout.setBackgroundColor(0x00000000);
linearLayout.setOrientation(LinearLayout.VERTICAL);
textView = new TextView(context);
textView.setText("");
LinearLayout.LayoutParams layoutParams_tv = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, margins);
layoutParams_tv.gravity=Gravity.BOTTOM;
linearLayout.addView(textView,layoutParams_tv);
2,RelativeLayout布局的创建和属性设置,并往里面添加子控件。
//父控件
reLayout = new RelativeLayout(context);
//半透明e0000000
reLayout.setBackgroundColor(0x00000000);
reLayout.setAlpha(100);
RelativeLayout.LayoutParams mLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT); ImgUrl.setLayoutParams(mLayoutParams); ImgUrl.setScaleType(ScaleType.FIT_CENTER); ImgUrl.setBackgroundResource(0); ImgUrl.setImageBitmap(bitmapBanner);
ImgUrl.setId(102);
reLayout.addView(ImgUrl);
txtClose = new ImageView(context);
RelativeLayout.LayoutParams mLayoutParams1 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
mLayoutParams1.addRule(RelativeLayout.ALIGN_TOP, ImgUrl.getId());
mLayoutParams1.addRule(RelativeLayout.ALIGN_RIGHT, ImgUrl.getId());
txtClose.setImageBitmap(BitmapFactory.decodeByteArray(closeByte, 0, closeByte.length));
txtClose.setScaleType(ScaleType.FIT_CENTER);
txtClose.setId(100);
if(type == Configuration.ORIENTATION_LANDSCAPE){
mLayoutParams1.width = ScreenUtil.dip2px(context, 30);
mLayoutParams1.height= ScreenUtil.dip2px(context, 30);
}else if (type == Configuration.ORIENTATION_PORTRAIT){
mLayoutParams1.width = ScreenUtil.dip2px(context, 35);
mLayoutParams1.height= ScreenUtil.dip2px(context, 35);
}
reLayout.addView(txtClose,mLayoutParams1);