android – 相对布局宽度/高度不能以编程方式工作?
作者:互联网
我想以编程方式进行相对布局并设置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);`
屏幕:
解决方法:
btn.getLayoutParams().width = width;
btn.getLayoutParams().height = height;
事实上,只是使用
RelativeLayout.LayoutParams rel_btn = new RelativeLayout.LayoutParams(
60, 60);
没关系.问题可能是背景图片拉伸按钮
标签:android,android-layout,android-ui 来源: https://codeday.me/bug/20190729/1574312.html