2013-03-26 56 views
0

請與本Scala的類幫助我,我要實現它的Java這裏,它是: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

+2

'返回View.MeasuresSpect.getSize(..)'和「沒關係」。 – 2013-03-26 20:38:23

回答

2

我認爲你需要爲measure做這樣的事情:

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

謝謝,但specMode變量呢?我只是返回'View.MeasureSpec.getSize(measureSpec)'使用你的代碼很奇怪。 – 2013-03-26 20:46:24

+0

這就是你發佈的scala代碼正在做的事情。所以是的,斯卡拉代碼也有點奇怪。 – Noah 2013-03-26 20:47:30

+0

嗯..無論如何。 – 2013-03-26 20:48:56