I need to center a imageview on the screen, but programatically, without using XML layouts.
I am actually using a FrameLayout, but i dont know how to center it on the FrameLayout.
This is the code i have until now:
FrameLayout fl = new FrameLayout(this.getApplicationContext());
splash = new ImageView(getApplicationContext());
splash.setImageResource(R.drawable.logo);
splash.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
fl.addView(splash);
fl.setBackgroundColor(Color.BLACK);
setContentView(fl);
I would think something like this would get it done for you:
LayoutParams centerParams = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
centerParams.gravity = Gravity.CENTER;
fl.setLayoutParams(centerParams);
check out this page for more info
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With