今天在开发过程中遇到一个问题,弄了好久都没有解决好
我在布局文件里面有这样一个
在布局文件里面直接写,EditText能够根据这个背景图片input_bg的大小正常显示。但是我在代码里面动态生成EditText,在给这个EidtText设置这张背景图片,EidtText不能够根据图片大小显示了。
我代码是这样写的
LinearLayout.LayoutParams layParams = new LinearLayout.LayoutParams(
LayoutParams.WARP_CONTENT,LayoutParams.WARP_CONTENT);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.HORIZONTAL);
EditText txt = new EditText(this);
txt. setBackgroundResource(R.drawable.input_bg);
Layout.addView(txt,layParams):
laycontainer.addView(layout); // laycontainer是最外面的LinearLayout
急用中,在线等待,求解决办法