2012-11-29 31 views
1

我有一個滾動查看我添加它我的自定義視圖,在customview覆蓋onMeasure & onTouchEvent但當我滾動它什麼都沒有畫。canvas.getHeight等於view.getHeight在平板設備上

protected final void onDraw(Canvas paramCanvas) 
    {  
    int text_width; 
    int yCanvas; 
    yCanvas = paramCanvas.getClipBounds().top; 
    int h = paramCanvas.getClipBounds().height() ; 
    int hView = this.getHeight() ; 
    int topView = this.getTop(); 
    paramCanvas.drawText("text...yCanvas :"+yCanvas + " --- hCanvas:"+h +"--- hView" + hView + " ----topView"+topView, 20, yCanvas+200, new Paint()); 

    } 

@Override 
public boolean onTouchEvent(MotionEvent event) { 
    boolean res = super.onTouchEvent(event); 
    postInvalidate(); 
    System.out.println("result: " + res); 
    return res; 
} 
@Override 
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  
    int h = 1000; 
    setMeasuredDimension(View.MeasureSpec.getSize(widthMeasureSpec), h);} 

有趣的是,在所有的片劑mycanvas高度是可觀看的高度,但在其他裝置canvas.heigh等於()是與喚起注意顯示exactullay相等。

回答

0

你的問題可能是,爲什麼你看不到任何東西被繪製。

你可能想看看你的Paint對象,它基本上沒有設置有意義的值。你可以創建一個成員變量並設置你需要的所有屬性(顏色等)。每次調用drawText(或其他繪製方法)時重用該對象。

編輯: 如果Paint對象不是問題;)您可能需要仔細檢查正在構建的座標。您正在使用ScrollView - 所以也許這是關於canvas.getClipBounds。爲什麼不在0,0上繪製文字?

+0

我設置了這個參數,但我沒有回覆。 ( –

+0

也許這個位置是一個問題?或者是你在'onMeasure'中做了些什麼(固定的'1000'看起來很可疑) – Brian

+0

我把它放在位置上( 0)在第一次我的文字畫,但是當我滾動不工作。在模擬器和其他設備(索尼,三星)工作正常,但當我在三星平板電腦(P5100)運行不工作 –

相關問題