Nul*_*ion 4 layout android imageview
我需要将一个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);
Run Code Online (Sandbox Code Playgroud)
我认为这样的事情会让你完成它:
LayoutParams centerParams = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
centerParams.gravity = Gravity.CENTER;
fl.setLayoutParams(centerParams);
Run Code Online (Sandbox Code Playgroud)
查看此页面了解更多信息
归档时间: |
|
查看次数: |
6645 次 |
最近记录: |