Reputation: 13
Actual display, its height should be three rows, but only two rows?
myView = new ImageView(mContext) //or new TextView();
int height = 128 * 3;
int width = 128;
RelativeLayout.LayoutParams layoutParams;
layoutParams = new RelativeLayout.LayoutParams(width, height);
layoutParams.setMargins(xxx, xxx);
myView.setBackground(xxx);
Upvotes: 1
Views: 67
Reputation: 2290
Try:
layoutParams = new RelativeLayout.LayoutParams
(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
myView.setScaleType(ImageView.ScaleType.FIT_XY);
Full Code:
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);
Also See:
https://developer.android.com/reference/android/widget/ImageView.ScaleType.html
Upvotes: 0
Reputation: 1692
You're using pixels ,,, try this
final float scale = getResources().getDisplayMetrics().density;
int height = (int) 128 * 3 * scale;
int width = (int) 128 * scale;
Upvotes: 1