2012-12-26 29 views
5

有兩個圖像黑色和藍色,而在藍色圖像上觸摸它應該填充像進度,我使用多個切割圖像,而不使用畫布,但沒有得到smoothness觸摸,如100 Pushups application填寫像seekbar兩個圖像疊加圖像視圖的觸摸事件

其實我試圖達到像上面提到的100俯臥撐應用類似,我得到了一個link,但這是使用畫布和我想實現使用圖像,我谷歌但沒有運氣,任何鏈接或教程類似到那個應用程序(100俯臥撐)?

enter image description here

+0

什麼是您的實際問題..? – Veger

+0

@Veger當我觸摸圖像並像seekbar一樣滾動時,第二張圖像將顯示爲觸摸。 – kyogs

回答

4

這是我想出了使用剪輯路徑的東西。我使用的是以下圖像(編碼器顏色),其中背景是純色的,前景色只包含透明背景上的藍色圓圈。將第一個背景圖像繪製到屏幕上,然後設置剪輯路徑,以便在其上方正確繪製前景圖像。

背景圖片; http://i.imgur.com/Sf6kg.png
前景圖像; http://i.imgur.com/Svtoh.png

並且代碼;

private class ProgressView extends View { 

    private Bitmap bgBitmap; 
    private Bitmap fgBitmap; 
    private RectF fullRect = new RectF(); 
    private Path clipPath = new Path(); 

    public ProgressView(Context context) { 
     super(context); 
     bgBitmap = BitmapFactory.decodeResource(
            context.getResources(), R.drawable.bg); 
     fgBitmap = BitmapFactory.decodeResource(
            context.getResources(), R.drawable.fg); 
    } 

    @Override 
    public void onDraw(Canvas c) { 
     fullRect.right = getWidth(); 
     fullRect.bottom = getHeight(); 

     c.drawBitmap(bgBitmap, null, fullRect, null); 

     float angle = SystemClock.uptimeMillis() % 3600/10.0f; 

     clipPath.reset(); 
     clipPath.setLastPoint(getWidth()/2, getHeight()/2); 
     clipPath.lineTo(getWidth()/2, getHeight()); 
     clipPath.arcTo(fullRect, -90, angle); 
     clipPath.lineTo(getWidth()/2, getHeight()/2); 
     c.clipPath(clipPath); 

     c.drawBitmap(fgBitmap, null, fullRect, null); 

     invalidate(); 
    } 
} 

如果用適當的方式替換我的臨時圖像並更新角度不是太困難。

+2

你做了我的一天!謝謝!:) – kyogs

+0

請不要使用此代碼!剪輯非常慢,在Android上看起來很糟糕。你最好先把它正確地畫出來! –

+0

@ Chris.Jenkins同意,最好不要使用剪裁,但是你的意思是_looks awful_? – harism

1

這將是一個自定義視圖,並且將處理onTouchEvent()方法,並且當用戶觸摸視圖將重繪。

onDraw()方法將檢查類似:

if(mIsBeingTouched){ 
    //set colour to touched 
} 
doDraw(canvas); 
///.... 

因此,當用戶觸摸的觀點,我會遞增計數,然後增加電弧計數。

final float arcDistance = mCurrentCount * 3.6; //Based on a max of 100 
canvas.drawArc(mBoundsRectF, 0f, mCurrentCount, mPaint); 

然後,根據計數繪製。

+0

謝謝,,,,但我不使用color.in我的情況有兩個圖像。 – kyogs

+0

提供示例代碼,我可以提供示例答案。 –

+0

我做了這個使用clippath.but作爲你說不使用這個。 – kyogs