Android 动态图像按钮换行内容不换行内容

Android 动态图像按钮换行内容不换行内容,android,imagebutton,Android,Imagebutton,我用代码创建了一个android imagebutton,并向其中添加了一个图像源。 imagebutton的layoutparams是包装内容 `LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); public ImageButton createActionBarItem(int id, int img, String tag){ ImageBut

我用代码创建了一个android imagebutton,并向其中添加了一个图像源。 imagebutton的layoutparams是包装内容

`LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
public ImageButton createActionBarItem(int id, int img, String tag){
ImageButton btnImage = new ImageButton(context);
btnImage.setLayoutParams(layoutParams);
btnImage.setImageResource(img);
btnImage.setId(id);
btnImage.setTag(tag);
return btnImage;
}`
我遇到的问题是,imagebackground甚至默认背景都比imageResource小
有没有办法让imageButtonBackground伸展一下,这样就可以把可拉伸的图像放进去?

位图存放在哪里?也许你的设备是hdpi,你只把位图放在mdpi或ldpi目录中-在这种情况下,图像将被缩小,只有在我的hdpi目录中,我的设备是mdpi,不要认为这应该是问题所在,因为我可以清楚地看到图像超出了背景的边界。我解决了这个问题,或者至少使用了一种解决方法:我知道将imagedrawable放在按钮的背景中,并将其放在我给出原始背景的相对位置