请帮我解决这个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
答案 0 :(得分:2)
我认为你需要对measure
执行类似的操作:
public int measure(int measureSpec) {
int specMode = View.MeasureSpec.getMode(measureSpec)
return View.MeasureSpec.getSize(measureSpec);
}