在 android 中查看没有单击按钮的实例

View instance without button click in android

我正在使用 vidyo 在我的 android 应用程序中实现视频通话。 如何在加载新意图时创建视图实例?

我有一个按钮,单击它我可以执行所需的操作。 它是这样定义的。

public void Start(View v){
   vc = new Connector(videoFrame, Connector.ConnectorViewStyle.VIDYO_CONNECTORVIEWSTYLE_Default,
                16, "warning all@VidyoConnector info@VidyoClient", "", 0);
   vc.showViewAt(videoFrame, 0, 0, videoFrame.getWidth(), videoFrame.getHeight());
   }

但是现在,我希望在不单击按钮的情况下执行相同的操作。

它应该在 onCreate() 中发生,但这是失败的。我无法查看相机预览。还有什么可以做的?

可能是你的videoFrame还没有布局。 您需要确保视图在使用 getWidthgetHeight 方法之前完成布局,为此您可以使用例如OnglobalLayoutListener.

videoFrame.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
// YOUR CODE GOES HERE
videoFrame.getViewTreeObserver().removeOnGlobalLayoutListener(this);
    }
});