0

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);
  • If you want to set it in code, you can use [this thread][1] [1]: http://stackoverflow.com/a/2965807/876603 – dors Jun 29 '13 at 19:34

2 Answers2

2

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);
Caner
  • 57,267
  • 35
  • 174
  • 180
0
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.

Triode
  • 11,309
  • 2
  • 38
  • 48