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);

相关内容

热门资讯

透视代打"wepok... 透视代打"wepoker一直输的号能继续打吗"竞技联盟辅助插件(竟然真的是有辅助下载)-哔哩哔哩1)...
今天下午"hhpok... 今天下午"hhpoker德州透视"werplan外卦神器(其实真的是有辅助工具)-哔哩哔哩1、hhp...
透视脚本"哈糖大菠萝... 透视脚本"哈糖大菠萝攻略"wepoker辅助器怎么弄(真是有辅助工具)-哔哩哔哩1、很好的工具软件,...
据权威媒体报道"aa... 据权威媒体报道"aapoker辅助插件工具"菠萝德州透视脚本(竟然是有辅助软件)-哔哩哔哩1、金币登...
相较于以往"约局吧开... 相较于以往"约局吧开挂"hh poker辅助有用吗(切实存在有辅助神器)-哔哩哔哩所有人都在同一条线...
目前来看"wepok... 目前来看"wepoker有透视底牌吗"如何下载德普之星辅助软件(切实有辅助工具)-哔哩哔哩1、如何下...
透视模拟器"哈糖大菠... 透视模拟器"哈糖大菠萝能开挂吗"wepoker透视脚本视频(确实真的是有辅助辅助器)-哔哩哔哩1、进...
网友热议"aapok... 网友热议"aapoker万能辅助器"pokemmo脚本辅助(原来真的有辅助下载)-哔哩哔哩1、每一步...
随着"德扑HHpok... 随着"德扑HHpoker有挂吗"wepoker怎么破解游戏(竟然真的有辅助工具)-哔哩哔哩1、每一步...
备受关注的"hhpo... 备受关注的"hhpoker辅助软件是真的么"wepoker怎么开辅助(真是真的有辅助辅助器)-哔哩哔...