开发者

shrinking surfaceview to be in a box

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜