Eurohardware
Eurohardware

Reputation: 19

Adjust the Size of an ImageView

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

Answers (2)

Triode
Triode

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

Caner
Caner

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

Related Questions