shrinking surfaceview to be in a box
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'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));
精彩评论