AndroidVideoView的scaleX,scaleY不起作用
创始人
2024-08-22 00:30:08
0

可以通过编写自定义View,覆盖VideoView的默认行为来解决这个问题。以下是一个示例代码:

public class ScalableVideoView extends VideoView {

    private int mVideoWidth;
    private int mVideoHeight;

    public ScalableVideoView(Context context) {
        super(context);
    }

    public ScalableVideoView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ScalableVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        if (mVideoWidth == 0 || mVideoHeight == 0) {
            setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight());
        } else {
            int width = getMeasuredWidth();
            int height = getMeasuredHeight();
            float scaleX = (float) mVideoWidth / (float) width;
            float scaleY = (float) mVideoHeight / (float) height;
            float scale = Math.max(scaleX, scaleY);
            width = (int) ((float) mVideoWidth / scale);
            height = (int) ((float) mVideoHeight / scale);
            setMeasuredDimension(width, height);
        }
    }

    public void setVideoSize(int videoWidth, int videoHeight) {
        mVideoWidth = videoWidth;
        mVideoHeight = videoHeight;
        requestLayout();
    }
}

您可以将此自定义视图放在XML中,并像VideoView一样使用它。要指定视频的大小,请使用setVideoSize()方法:

mScalableVideoView.setVideoSize(videoWidth, videoHeight);

相关内容

热门资讯

9分钟了解!蜀渝牌乐汇挂机软件... 9分钟了解!蜀渝牌乐汇挂机软件,wepoker代打辅助机器人,我来教教你(有挂教学);是一款可以让一...
发现玩家!哈局八张有没有透视挂... 发现玩家!哈局八张有没有透视挂,hhpoker有后台操控吗,曝光教程(详细教程)是一款可以让一直输的...
揭秘关于!仙桃晃晃辅助器,we... 揭秘关于!仙桃晃晃辅助器,wepoker辅助器安装包,黑科技教程(有挂教程);揭秘关于!仙桃晃晃辅助...
最新研发!微信小程序功夫川辅助... 最新研发!微信小程序功夫川辅助,wepokerplus脚本,科技教程(有挂秘诀)是一款可以让一直输的...
技巧知识分享!来几局辅助器开挂... 技巧知识分享!来几局辅助器开挂,hhpoker辅助挂是真的吗,揭秘教程(有挂秘诀)是一款可以让一直输...
玩家必用!哥哥打大a辅助神器,... 玩家必用!哥哥打大a辅助神器,hhpoker真的有透视吗,透明挂教程(有挂工具)是一款可以让一直输的...
发现玩家!贪玩互娱辅助,wej... 发现玩家!贪玩互娱辅助,wejoker内置辅助,第三方教程(新版有挂)是一款可以让一直输的玩家,快速...
揭秘关于!小程序微乐游戏辅助器... 揭秘关于!小程序微乐游戏辅助器,wepoker轻量版有透视吗,黑科技教程(有挂头条);1、很好的小程...
我来教教大家!微乐家乡游戏攻略... 我来教教大家!微乐家乡游戏攻略,wepoker-h5下载,透牌教程(有挂实锤);微乐家乡游戏攻略软件...
每日必备!网上微乐家乡微信版辅... 每日必备!网上微乐家乡微信版辅助器,wepoker软件辅助程序,切实教程(有挂方法);人气非常高,a...