我想从
更改我的应用中的当前SurfaceView
到
有没有办法在不使用main.xml
的情况下执行此操作?
我正在尝试在运行时编写GUI。我可以通过覆盖SurfaceView
并使用onMeasure()
来获得当前setMeasuredDimension()
(顶部图片),但我希望获得底部图片。绿色区域是屏幕的其余部分。
编辑:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
this.setMeasuredDimension(500, 300);
param.gravity = Gravity.CENTER_VERTICAL;
}
答案 0 :(得分:1)
您是否尝试过使用android:layout_gravity
- 属性将视图置于布局中心?
相应的类将为FrameLayout.LayoutParams
,可能的重力列为here。然后代码看起来像这样:
FrameLayout f = new FrameLayout(this);
ImageView test = new ImageView(this);
f.addView(test, new FrameLayout.LayoutParams(500, 300, Gravity.CENTER));