【问题标题】:set SurfaceView's margin programmatically以编程方式设置 SurfaceView 的边距
【发布时间】:2014-11-26 03:54:38
【问题描述】:

我在我的布局 xml 文件中添加相机的“SurfaceView”,

<SurfaceView
        android:id="@+id/preview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="95dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"/>

但我想动态设置 ma​​rginTop。如果我想以编程方式设置 SurfaceView 的 ma​​rginTop,我该怎么做?

我在互联网上搜索过。但我没有得到任何答复。所以任何人都可以帮助我做到这一点。

【问题讨论】:

标签: android layout surfaceview


【解决方案1】:

你可能会这样做:

int margin = getResources().getDimensionPixelSize(R.dimen.surface_view_margin);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
lp.setMargins(margin, 0, 0, 0);
surfaceView.setLayoutParams(lp);

这有帮助吗?

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-24
  • 2011-01-29
  • 2019-02-08
  • 2019-10-19
  • 1970-01-01
  • 2016-12-23
相关资源
最近更新 更多