How to center an imageView on the screen via code?

Asked

Viewed 284 times

0

I created a imageViewvia code and would like to know how to center it on the screen

1 answer

3


Hello,

This will depend on the type of layout you’re using.But try using this one:

LinearLayout.LayoutParams mLayoutParams=new LinearLayout.LayoutParams(width, height);
mLayoutParams.gravity=Gravity.CENTER;
ImageView.setLayoutParams(layoutParams);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.