gpt4 book ai didi

java - Scala 的类转为 Java

转载 作者:行者123 更新时间:2023-12-02 07:10:00 25 4
gpt4 key购买 nike

请帮我解决这个 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 上实现它有什么建议吗?

这是包含此代码的原始文章: original code

最佳答案

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

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

关于java - Scala 的类转为 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15646896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com