Reputation: 19
How do i adjust the Size and Position of an ImageView?
my code:
int id = R.drawable.x;
X = new ImageView(this);
X.setImageResource(id);
screen.addView(X);
Upvotes: 0
Views: 1980
Reputation: 11357
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.x);
MarginLayoutParams params = new MarginLayoutParams(width, height);
params.setMargins(left, top, right, bottom);
imageView.setLayoutParams(params);
screen.addView(imageView);
width : provide the width you wanted
height : height of the view
left,top,right,bottom : to set the x,y position set the left margin and top margin.
You can also set the image scaleType. For more info on ScaleType see the developer doc.
Upvotes: 0
Reputation: 59288
Try like this:
X = new ImageView(this);
X.setImageResource(R.drawable.x;);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(100, 100);
X.setLayoutParams(layoutParams);
screen.addView(X);
Upvotes: 2