我需要以编程方式将一个ImageView居中在屏幕上,而不使用XML布局。
实际上,我正在使用FrameLayout,但是我不知道如何将其居中在FrameLayout上。
以下是我到目前为止所拥有的代码:
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);