layout = (FrameLayout) findViewById(R.id.framelayout);
//移除所有的view
//layout.removeAllViews();
//计算出屏幕的宽和高
int screen_w = getResources().getDisplayMetrics().widthPixels;
int screen_h = getResources().getDisplayMetrics().heightPixels;
image1 = new ImageView(Recycle.this);
//设置View的属性
FrameLayout.LayoutParams params1 = new FrameLayout.LayoutParams(screen_w/2,screen_h/2);
image1.setLayoutParams(params1);
image1.setImageResource(R.mipmap.banner_a);
layout.addView(image1);
image2 = new ImageView(Recycle.this);
FrameLayout.LayoutParams params2 = new FrameLayout.LayoutParams(screen_w/2,screen_h/2);
params2.leftMargin = screen_w/8;
image2.setLayoutParams(params2);
image2.setImageResource(R.mipmap.banner_b);
layout.addView(image2);
代码中设置View
最新推荐文章于 2021-02-11 16:03:34 发布