0

请帮助我处理这个 Scala 的类,我想在 Java 上实现它,它是:

class StretchVideoView(context:Context, attr:AttributeSet)
extends VideoView(context, attrib) {
    def measure(measureSpec:Int):Int = {
        val specMode = View.MeasureSpec.getMode(measureSpec)
        View.MeasureSpec.getSize(measureSpec)
    }

    override def onMeasure(widthMeasureSpec:Int, heightMeasureSpec:Int) {
        val (w,h) = (measure(widthMeasureSpec), measure(heightMeasureSpec))
        getHolder().setFixedSize(w,h)
       super.onMeasure(widthMeasureSpec, heightMeasureSpec)
    }
}

我也尝试自己做,这是我的 Java 代码:

class StretchVideoView extends VideoView {

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

    public int measure(int measureSpec) {
        int specMode = View.MeasureSpec.getMode(measureSpec)
        ??? View.MeasureSpec.getSize(measureSpec); // may be + here ???

        return specMode;  // ???
    }

        // and I'm not sure about this
    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {    
        int w = measure(widthMeasureSpec);
        int h = measure(heightMeasureSpec);
        getHolder().setFixedSize(w,h);
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);   
    }
}

任何建议如何在Java上实现它?

这是带有此代码的原始文章: 原始代码

4

1 回答 1

2

我认为你需要做这样的事情measure

public int measure(int measureSpec) {
    int specMode = View.MeasureSpec.getMode(measureSpec)
    return View.MeasureSpec.getSize(measureSpec);
}
于 2013-03-26T20:38:51.280 回答