将表面视图缩小到一个盒子中
我想将应用程序中当前的 SurfaceView
从
更改为
有没有办法在不使用 main.xml
的情况下做到这一点?
我正在尝试在运行时编写 GUI 代码。我可以通过覆盖 onMeasure()
并使用 setMeasuredDimension()
来实现当前的 SurfaceView
(上图),但我想实现底部图片。绿色区域是屏幕的其余部分。
编辑:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
this.setMeasuredDimension(500, 300);
param.gravity = Gravity.CENTER_VERTICAL;
}
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.gravity = Gravity.CENTER_VERTICAL;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用 android:layout_gravity 属性将视图置于布局中心?
相应的类将是
FrameLayout.LayoutParams
,可能的重力列于此处。代码可能如下所示: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: