简体   繁体   English

Scala的Java类

[英]Scala's class to Java

Please help me with this Scala's class I want to implement it on Java here it is: 请帮我解决这个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)
    }
}

I also tried to do it myself here is my Java code: 我也尝试自己做这里是我的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);   
    }
}

Any suggestions how to implement it on Java? 有关如何在Java上实现它的任何建议?

Here's the original article with this code: original code 这是使用此代码的原始文章: 原始代码

I think you need to do something like this for measure : 我认为你需要做这样的事情来measure

public int measure(int measureSpec) {
    int specMode = View.MeasureSpec.getMode(measureSpec)
    return View.MeasureSpec.getSize(measureSpec);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM