开发者

shrinking surfaceview to be in a box

开发者 https://www.devze.com 2023-03-28 03:13 出处:网络
I would like to change the current SurfaceView in my app from to Is there a way to do this without using main.xml at all?

I would like to change the current SurfaceView in my app from

shrinking surfaceview to be in a box

to

shrinking surfaceview to be in a box

Is there a way to do this without using main.xml at all?

I'm trying to code the GUI in run-time. I can achieve the current SurfaceView (top picture) by overriding onMeasure() and using setMeasuredDimension(), but I would like to achieve the bottom picture. The green area is the rest of the screen.

EDIT:

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 
{
    this.setMeasuredDimension(500, 300);
    param.gra开发者_JS百科vity = Gravity.CENTER_VERTICAL;
}   


Have you tried using the android:layout_gravity-attribute to center your View in the Layout?

The corresponding class would be FrameLayout.LayoutParams, possible gravity's are listed here. The code could then look something like this:

FrameLayout f = new FrameLayout(this);
ImageView test = new ImageView(this);
f.addView(test, new FrameLayout.LayoutParams(500, 300, Gravity.CENTER));
0

精彩评论

暂无评论...
验证码 换一张
取 消