调整布局
音视频通话 UIKit 目前支持画中画(picture-in-picture)布局和宫格式(gallery)布局,每种布局都有自己的配置。
如需选择和配置布局,请在 ZegoUIKitPrebuiltCallConfig
中使用 layout
参数。
画中画布局
画中画布局支持配置 switchLargeOrSmallViewByClick
,允许用户点击小视图以实现在大视图和小视图之间切换。默认为允许。
效果如下:
当摄像头关闭时显示我的视图 | 当摄像头关闭时隐藏我的视图 | 切换 |
---|---|---|
以下是参考代码:
基本呼叫
携带邀请的呼叫
public class CallActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_call);
long appID = YourAppID;
String appSign = YourAppSign;
String userID = "userID";
String userName = "userName";
String callID = "testCallID";
// 在这里修改自定义配置。
ZegoUIKitPrebuiltCallConfig config = ZegoUIKitPrebuiltCallConfig.oneOnOneVideoCall();
ZegoLayoutPictureInPictureConfig pipConfig = new ZegoLayoutPictureInPictureConfig();
pipConfig.switchLargeOrSmallViewByClick = true;
config.layout.mode = ZegoLayoutMode.PICTURE_IN_PICTURE;
config.layout.config = pipConfig;
ZegoUIKitPrebuiltCallFragment fragment = ZegoUIKitPrebuiltCallFragment
.newInstance(appID, appSign, callID, userID, userName, config);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, fragment)
.commitNow();
}
}
1
public class MainActivity extends AppCompatActivity {
long appID = YourAppID;
String appSign = YourAppSign;
String userID = "userID";
String userName = "userName";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initCallInviteService();
}
public void initCallInviteService() {
ZegoUIKitPrebuiltCallInvitationConfig callInvitationConfig = new ZegoUIKitPrebuiltCallInvitationConfig();
callInvitationConfig.provider = new ZegoUIKitPrebuiltCallConfigProvider() {
@Override
public ZegoUIKitPrebuiltCallConfig requireConfig(ZegoCallInvitationData invitationData) {
ZegoUIKitPrebuiltCallConfig config;
boolean isVideoCall = invitationData.type == ZegoInvitationType.VIDEO_CALL.getValue();
boolean isGroupCall = invitationData.invitees.size() > 1;
if (isVideoCall && isGroupCall) {
config = ZegoUIKitPrebuiltCallConfig.groupVideoCall();
} else if (!isVideoCall && isGroupCall) {
config = ZegoUIKitPrebuiltCallConfig.groupVoiceCall();
} else if (!isVideoCall) {
config = ZegoUIKitPrebuiltCallConfig.oneOnOneVoiceCall();
} else {
config = ZegoUIKitPrebuiltCallConfig.oneOnOneVideoCall();
}
// 在这里修改您的自定义呼叫配置。
if(isGroupCall){
ZegoLayoutGalleryConfig galleryConfig = new ZegoLayoutGalleryConfig();
galleryConfig.addBorderRadiusAndSpacingBetweenView = false;
config.layout.mode = ZegoLayoutMode.GALLERY;
config.layout.config = galleryConfig;
}else{
ZegoLayoutPictureInPictureConfig pipConfig = new ZegoLayoutPictureInPictureConfig();
pipConfig.switchLargeOrSmallViewByClick = true;
config.layout.mode = ZegoLayoutMode.PICTURE_IN_PICTURE;
config.layout.config = pipConfig
}
return config;
}
);
ZegoUIKitPrebuiltCallService.init(getApplication(), appID, appSign, userID, userName,
callInvitationConfig);
}
@Override
protected void onDestroy() {
super.onDestroy();
ZegoUIKitPrebuiltCallService.logout();
}
}
1
宫格式布局
宫格式布局支持的配置是:
addBorderRadiusAndSpacingBetweenView
:在宫格式布局中,可以使用此选项添加边框圆角半径和视图之间的间距。true:启用(默认)。false:禁用。
效果如下:
添加边框圆角半径和间距 | 不添加边框圆角半径和间距 |
---|---|
基本呼叫
携带邀请的呼叫
public class CallActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_call);
long appID = YourAppID;
String appSign = YourAppSign;
String userID = "userID";
String userName = "userName";
String callID = "testCallID";
// 在这里修改自定义配置。
ZegoUIKitPrebuiltCallConfig config = ZegoUIKitPrebuiltCallConfig.groupVideoCall();
ZegoLayoutGalleryConfig galleryConfig = new ZegoLayoutGalleryConfig();
galleryConfig.addBorderRadiusAndSpacingBetweenView = false;
config.layout.config = galleryConfig;
ZegoUIKitPrebuiltCallFragment fragment = ZegoUIKitPrebuiltCallFragment
.newInstance(appID, appSign, callID, userID, userName, config);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, fragment)
.commitNow();
}
}
1
public class MainActivity extends AppCompatActivity {
long appID = YourAppID;
String appSign = YourAppSign;
String userID = "userID";
String userName = "userName";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initCallInviteService();
}
public void initCallInviteService() {
ZegoUIKitPrebuiltCallInvitationConfig callInvitationConfig = new ZegoUIKitPrebuiltCallInvitationConfig();
callInvitationConfig.provider = new ZegoUIKitPrebuiltCallConfigProvider() {
@Override
public ZegoUIKitPrebuiltCallConfig requireConfig(ZegoCallInvitationData invitationData) {
ZegoUIKitPrebuiltCallConfig config;
boolean isVideoCall = invitationData.type == ZegoInvitationType.VIDEO_CALL.getValue();
boolean isGroupCall = invitationData.invitees.size() > 1;
if (isVideoCall && isGroupCall) {
config = ZegoUIKitPrebuiltCallConfig.groupVideoCall();
} else if (!isVideoCall && isGroupCall) {
config = ZegoUIKitPrebuiltCallConfig.groupVoiceCall();
} else if (!isVideoCall) {
config = ZegoUIKitPrebuiltCallConfig.oneOnOneVoiceCall();
} else {
config = ZegoUIKitPrebuiltCallConfig.oneOnOneVideoCall();
}
// 在这里修改自定义呼叫配置。
if(isGroupCall){
ZegoLayoutGalleryConfig galleryConfig = new ZegoLayoutGalleryConfig();
galleryConfig.addBorderRadiusAndSpacingBetweenView = false;
config.layout.config = galleryConfig;
}else{
ZegoLayoutPictureInPictureConfig pipConfig = new ZegoLayoutPictureInPictureConfig();
pipConfig.switchLargeOrSmallViewByClick = true;
config.layout.config = pipConfig;
}
return config;
}
);
ZegoUIKitPrebuiltCallService.init(getApplication(), appID, appSign, userID, userName,
callInvitationConfig);
}
@Override
protected void onDestroy() {
super.onDestroy();
ZegoUIKitPrebuiltCallService.logout();
}
}
1