How to center an imageview on screen via code? [closed]

0

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

    
asked by anonymous 03.03.2016 / 13:07

1 answer

3

Hello,

This will depend on the type of layout you are using. But try using this:

LinearLayout.LayoutParams mLayoutParams=new LinearLayout.LayoutParams(width, height);
mLayoutParams.gravity=Gravity.CENTER;
ImageView.setLayoutParams(layoutParams);
    
03.03.2016 / 13:30