我想以编程方式进行相对布局并设置android:layout_widht = 60 android:layout_height = 60.当我以编程方式执行时,它是否填满所有屏幕?我怎样才能做到这一点?
我的代码:`
RelativeLayout relativeLayout=new RelativeLayout(getContext());
RelativeLayout.LayoutParams rel_btn = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rel_btn.height = 60;
rel_btn.width = 60;
relativeLayout.setLayoutParams(rel_btn);
this.setBackgroundResource(com.example.R.drawable.line);`
屏幕:
答案 0 :(得分:7)
btn.getLayoutParams().width = width;
btn.getLayoutParams().height = height;
实际上,只需使用
RelativeLayout.LayoutParams rel_btn = new RelativeLayout.LayoutParams(
60, 60);
没关系。问题可能是背景图片拉伸按钮