尝试:
layoutParams = new RelativeLayout.LayoutParams
(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
myView.setScaleType(ImageView.ScaleType.FIT_XY);
全码:
ImageView myView = new ImageView(this);
//int height = 128 * 3;
//int width = 128;
RelativeLayout.LayoutParams layoutParams;
layoutParams = new RelativeLayout.LayoutParams
(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(1, 1, 1, 1);
myView.setScaleType(ImageView.ScaleType.FIT_XY);
myView.setBackground(getDrawable(R.drawable.art_clouds));
RelativeLayout relativeLayout=new RelativeLayout(this);
relativeLayout.setLayoutParams(layoutParams);
relativeLayout.addView(myView);
setContentView(relativeLayout);
另请参见:
https://developer.android.com/reference/android/widget/ImageView.ScaleType.html
酷!有用!谢谢!!! –
@Mike_ShangJun如果答案的工作,那么你可以接受答案http://stackoverflow.com/help/someone-answers –
另请参阅:https://developer.android.com/reference/android/widget/ImageView.ScaleType。 HTML –