tencent cloud

User Generated Short Video SDK

Android

Download
聚焦模式
字号
最后更新时间: 2026-05-11 17:46:57

Feature Overview

TAVWidgetContentView is the view for gesture operations on all widgets (stickers, picture-in-picture, and other components, hereinafter collectively referred to as widgets). Widget selection, deselection, dragging, position interception, rotation angle interception, and other operations can all be performed in this class.

Related Interface Classes

Interface Class Name
Description
TAVEditor
SDK operation entry class.
TAVWidgetContentView
SDK gesture operation base class.

Widget Editing Process

When a gesture taps a widget, TAVWidgetContentView will call ITAVWidgetEditViewFactory methods to create widget edit views. Currently, there are two built-in basic edit views:
Sticker basic edit view: TAVStickerEditView
Picture-in-picture basic edit view: TAVPipEditView
Widget borders and operation buttons are drawn in the corresponding EditView. You can draw different edit frames for different widgets by inheriting the corresponding EditView.

Main Interface Introduction

Interface Name
Description
ITAVWidgetEventListener
Event interface for widget operations; widget activation, deactivation, dragging, clicking, and other events are called back through this interface.
ITAVWidgetTouchOutsideListener
Callback when no widget is tapped.
ITAVWidgetEditViewFactory
Factory for creating custom widget edit views.
ITAVWidgetMoveLimitProvider
Widget move limit strategy provider.

Main Method Introduction

Method Name
Description
setTouchable
Set whether gesture operations are enabled.
setNoFocusGestureEnabled
Set whether widgets can be dragged directly without selecting first.
setWidgetType
Set the types of widgets that can be operated.
setMoveRegionRect
Set the widget dragging region.
activeWidget
Activate the specified widget.
resignCurrentActive
Deactivate the currently active widget.
addWidgetEventListener
Add a widget operation event listener.
setWidgetTouchOutsideListener
Set the callback for when no widget is tapped.
setEditViewFactory
Set a custom widget edit view factory. If the SDK's default edit view does not meet business requirements, you can implement your own edit view.
setSyncWithRender
Set whether widget operations synchronize with rendering.
setMoveLimitProvider
Set the widget move limit strategy. You can specify the move limit mode and region for each widget.

Set Custom Sticker Edit View

1. First, implement your own sticker edit view.
public class MyStickerEditView extends TAVStickerEditView {
... your own logic
// To get the vertex positions of a widget in the View, use the getVertexPoints method
}
2. Then set the widget edit view factory for TAVWidgetContentView:
public class MyWidgetContentView extends TAVWidgetContentView {
public MyWidgetContentView(Context context) {
super(context);
setEditViewFactory(new ITAVWidgetEditViewFactory() {
@Override
public TAVStickerEditView createStickerEditView(TAVSticker sticker) {
return new MyStickerEditView(context, sticker);
}
...
});
}
}
3. Pass the custom TAVWidgetContentView when calling TAVEditor initWithPreview:
TAVEditor editor = TAVEditorFactory.createEditor();
TAVEditorConstants.PreviewParam param = new TAVEditorConstants.PreviewParam();
param.videoView = FrameLayout;
// Pass in custom TAVWidgetContentView
param.contentView = new MyWidgetContentView(context);
param.loopPlay = true;
param.autoPlay = true;
editor.initWithPreview(param);

Listen to Widget Gesture Events

public class MyWidgetContentView extends TAVWidgetContentView {
public MyWidgetContentView(Context context) {
super(context);
// Add widget event listener
addWidgetEventListener(new ITAVWidgetEventListener() {
@Override
public void onWidgetClick(TAVWidget widget, MotionEvent event) {
// Widget clicked
}

@Override
public void onWidgetTouchBegin(TAVWidget widget, MotionEvent event) {
// Widget drag started
}

@Override
public void onWidgetTouchEnd(TAVWidget widget, MotionEvent event) {
// Widget drag ended
}

@Override
public void onWidgetAdjust(TAVWidget widget, TAVWidgetOperationMode operationMode) {
// Widget is being dragged
}

@Override
public void onWidgetActive(TAVWidget widget) {
// Widget activated for editing
}

@Override
public void onWidgetResign(TAVWidget widget) {
// Widget deactivated
}
});
}
}

Advanced Operations

You need to override TAVWidgetContentView methods.

Customize TAVWidgetContentView Display Logic

@Override
protected boolean shouldShowEditView() {
// Add your own display logic
return super.shouldShowEditView();
}

@Override
protected void updateWidgetEditViewVisibility() {
if (null != currentEditView && null != currentWidget) {
final boolean shouldShow = shouldShowEditView();
// Modify TAVWidgetEditView visibility based on display conditions
}
}

Operation Interception

TAVWidgetContentView provides the following interfaces for widget interception:
Interface Name
Description
positionInterceptor
Widget position interception.
rotateInterceptor
Widget rotation angle interception.
scaleInterceptor
Widget scale interception.
The sample code demonstrates intercepting by overriding the positionInterceptor method to achieve position snapping during movement:
@Override
protected PointF positionInterceptor(float x, float y) {
PointF translation = new PointF(x, y);
PointF[] previewPoints = currentEditView.computeVertexPoints(translation);
float previewCenterX = (previewPoints[0].x + previewPoints[2].x) / 2f;
float previewCenterY = (previewPoints[0].y + previewPoints[2].y) / 2f;
float viewCenterX = getWidth() / 2f;
float viewCenterY = getHeight() / 2f;
float deltaX = viewCenterX - previewCenterX;
float deltaY = viewCenterY - previewCenterY;
// Snap when within 10 pixels
if (Math.abs(deltaX) <= 10) {
translation.x += deltaX;
}
if (Math.abs(deltaY) <= 10) {
translation.y += deltaY;
}
return translation;
}


帮助和支持

本页内容是否解决了您的问题?

填写满意度调查问卷,共创更好文档体验。

文档反馈