我想在 JAVA CODE 中创建一个全屏的RelativeLayout。
在这个RelativeLayout里面,我想要2个ImaveView,一个位于左上方,50个高度和50个重量,另一个位于左上角,并且#34; match_parent&#34 ;
现在我有了:
relativeLayout = new RelativeLayout(this);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
relativeLayout.setLayoutParams(lp);
im = new ImageView(this);
im.setLayoutParams(new LayoutParams(50,50));
im2 = new ImageView(this);
im2.setScaleType(ImageView.ScaleType.FIT_XY);
im2.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
relativeLayout.addView(im2);
relativeLayout.addView(im);
但是第一张图片没有显示,第二张图片只显示完整的重量。
答案 0 :(得分:1)
您可以查看此代码吗?
RelativeLayout relativeLayout = new RelativeLayout(this);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
relativeLayout.setLayoutParams(lp);
ImageView im = new ImageView(this);
im.setLayoutParams(new RelativeLayout.LayoutParams(50, 50));
im.setImageResource(R.color.accent);
ImageView im2 = new ImageView(this);
im2.setScaleType(ImageView.ScaleType.FIT_XY);
im2.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
im2.setImageResource(R.color.orderProcessing);
relativeLayout.addView(im2);
relativeLayout.addView(im);
setContentView(relativeLayout);